Advertisement
LeeMace

Quaternion to look/ follow object

Jun 26th, 2023
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.29 KB | Gaming | 0 0
  1. public class LookAtScript : MonoBehaviour
  2. {
  3.     public Transform target;
  4.     void Update() {
  5.         //object looks at whatever is attached to target
  6.         Vector3 relativePos = target.position - transform.position;
  7.         transform.rotation = Quaternion.LookRotation(relativePos);
  8.     }
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement