Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CameraFollow : MonoBehaviour
- {
- public Transform cameraPivot;
- public float posSmoothingX = 0.3f;
- public float posSmoothingY = 0.3f;
- public float posSmoothingZ = 0.3f;
- public float rotSmoothing = 0.1f;
- void FixedUpdate()
- {
- float smoothedPosX = Mathf.Lerp(transform.position.x, cameraPivot.position.x, posSmoothingX * Time.deltaTime);
- float smoothedPosY = Mathf.Lerp(transform.position.y, cameraPivot.position.y, posSmoothingY * Time.deltaTime);
- float smoothedPosZ = Mathf.Lerp(transform.position.z, cameraPivot.position.z, posSmoothingZ * Time.deltaTime);
- transform.position = new Vector3(smoothedPosX, smoothedPosY, smoothedPosZ);
- float smoothedRotX = Mathf.LerpAngle(transform.rotation.eulerAngles.x, cameraPivot.rotation.eulerAngles.x, rotSmoothing * Time.deltaTime);
- float smoothedRotY = Mathf.LerpAngle(transform.rotation.eulerAngles.y, cameraPivot.rotation.eulerAngles.y, rotSmoothing * Time.deltaTime);
- transform.rotation = Quaternion.Euler(new Vector3(smoothedRotX, smoothedRotY, 0f)); // azzero rotazioni asse x e z
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement