summaryrefslogtreecommitdiff
path: root/Other/NavMeshTest/Assets/Scripts/FaceTo.cs
blob: c809ca5276726505e491be1c9e50d52ca5495bd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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);
    }
}