Advertisement
Guest User

CameraFollow.cs

a guest
Nov 13th, 2020
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraFollow : MonoBehaviour
  6. {
  7.     public Transform cameraPivot;
  8.     public float posSmoothingX = 0.3f;
  9.     public float posSmoothingY = 0.3f;
  10.     public float posSmoothingZ = 0.3f;
  11.     public float rotSmoothing = 0.1f;
  12.  
  13.     void FixedUpdate()
  14.     {
  15.         float smoothedPosX = Mathf.Lerp(transform.position.x, cameraPivot.position.x, posSmoothingX * Time.deltaTime);
  16.         float smoothedPosY = Mathf.Lerp(transform.position.y, cameraPivot.position.y, posSmoothingY * Time.deltaTime);
  17.         float smoothedPosZ = Mathf.Lerp(transform.position.z, cameraPivot.position.z, posSmoothingZ * Time.deltaTime);
  18.         transform.position = new Vector3(smoothedPosX, smoothedPosY, smoothedPosZ);
  19.  
  20.         float smoothedRotX = Mathf.LerpAngle(transform.rotation.eulerAngles.x, cameraPivot.rotation.eulerAngles.x, rotSmoothing * Time.deltaTime);
  21.         float smoothedRotY = Mathf.LerpAngle(transform.rotation.eulerAngles.y, cameraPivot.rotation.eulerAngles.y, rotSmoothing * Time.deltaTime);
  22.         transform.rotation = Quaternion.Euler(new Vector3(smoothedRotX, smoothedRotY, 0f)); // azzero rotazioni asse x e z
  23.     }
  24.  
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement