Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. public class FollowCamera : MonoBehaviour {
  2.     public GameObject target;
  3.     public float damping = 1;
  4.     Vector3 offset;
  5.      
  6.     void Start() {
  7.         offset = target.transform.position - transform.position;
  8.     }
  9.      
  10.     void LateUpdate() {
  11.         float currentAngle = transform.eulerAngles.y;
  12.         float desiredAngle = target.transform.eulerAngles.y;
  13.         float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
  14.          
  15.         Quaternion rotation = Quaternion.Euler(0, angle, 0);
  16.         transform.position = target.transform.position - (rotation * offset);
  17.          
  18.         transform.LookAt(target.transform);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement