Delayed LookAt, but only on one axis

Hey,
after too many hours of trying multiple solutions, using Slerp, Lerp, LookAt, LookRotation and reading almost every answer on the forums I’m just really confused right now.

Basically what I want to achieve is an object that changes its rotation to look at another object over time. (with “over time” i mean that it should be rotation towards the endrotation and not just look at it every frame)
But this should only be happening on one axis (y-axis in this case).

I would very much appreciate your help.

Thank you in advance :slight_smile:

Patrick

Get the direction to the target, but ignore Y. From that direction, get a rotation quaternion. Rotate towards that rotation.

using UnityEngine;

public class LookAtXZ : MonoBehaviour
{
    public Transform lookAt;
    public float degreesPerSecond = 90;

    void LateUpdate()
    {
        if (!lookAt)
            return;

        Quaternion targetRotation = Quaternion.LookRotation(DirectionXZ());
        transform.rotation = Quaternion.RotateTowards(transform.rotation, 
            targetRotation, degreesPerSecond * Time.deltaTime);
    }

    Vector3 DirectionXZ()
    {
        Vector3 direction = lookAt.position - transform.position;
        direction.y = 0; // Ignore Y
        return direction;
    }
}