using UnityEngine;

public class DemonFaceMovement : MonoBehaviour
{
    [SerializeField] private Transform lookAtPoint;

    public float maxRotationDegrees = 2.0f;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        RotateTwowardsLookAtPoint();

    }

    private void RotateTwowardsLookAtPoint()
    {
        // Calculate the direction towards the target
        Vector3 direction = lookAtPoint.position - transform.position;
        // Normalize the direction
        direction = direction.normalized;

        // Calculate the rotation angle
        Quaternion targetRotation = Quaternion.FromToRotation(Vector3.up, direction);
        Quaternion finalRotation = Quaternion.RotateTowards(transform.rotation, targetRotation, maxRotationDegrees);

        transform.rotation = Quaternion.Euler(0, 0, finalRotation.eulerAngles.z);
    }

}
