Advertisement
CarlosWGama

CameraFollow 3D

Sep 9th, 2022
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class CameraFollow : MonoBehaviour
  4.  
  5. {
  6.     public Transform target;
  7.     public float smoothSpeed = 0.125f;
  8.     public Vector3 locationOffset;
  9.     public Vector3 rotationOffset;
  10.  
  11.     void FixedUpdate()
  12.     {
  13.         Vector3 desiredPosition = target.position + target.rotation * locationOffset;
  14.         Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
  15.         transform.position = smoothedPosition;
  16.  
  17.         Quaternion desiredrotation = target.rotation * Quaternion.Euler(rotationOffset);
  18.         Quaternion smoothedrotation = Quaternion.Lerp(transform.rotation, desiredrotation, smoothSpeed);
  19.         transform.rotation = smoothedrotation;
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement