Answers for "mathf.atan2 unityc#"

C#
0

mathf.atan2 unityc#

// Usually you use transform.LookAt for this.
// But this can give you more control over the angleusing UnityEngine;
using System.Collections;public class ExampleClass : MonoBehaviour
{
    public Transform target;    void Update()
    {
        Vector3 relative = transform.InverseTransformPoint(target.position);
        float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg;
        transform.Rotate(0, angle, 0);
    }
}
Posted by: Guest on October-04-2021

C# Answers by Framework

Browse Popular Code Answers by Language