diff options
Diffstat (limited to 'Other/NavMeshTest/Assets/Scripts/FaceTo.cs')
-rw-r--r-- | Other/NavMeshTest/Assets/Scripts/FaceTo.cs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Other/NavMeshTest/Assets/Scripts/FaceTo.cs b/Other/NavMeshTest/Assets/Scripts/FaceTo.cs new file mode 100644 index 0000000..c809ca5 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/FaceTo.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FaceTo : MonoBehaviour +{ + + public Transform target; + + void Update() + { + if (target == null) + return; + + Vector3 dir = target.position - transform.position; + dir = dir.normalized; + + Vector3 faceto = Vector3.ProjectOnPlane(dir, Vector3.up).normalized; + + transform.rotation = Quaternion.LookRotation(faceto, Vector3.up); + } +} |