[Solved] Object not centered with Smooth Look At

Hello,
I am using a script on a camera to track a moving object, it should be centered on the screen, but it is always on the right and a little low. Why?
Thanks

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SmoothLookAt : MonoBehaviour
{
    public Transform target;
    public float damping = 6.0f;
    public bool smooth = true;

    private void LateUpdate()
    {
        if (target != null)
        {
            if (smooth)
            {
                // Look at and dampen the rotation
                Quaternion rotation = Quaternion.LookRotation(target.position - transform.position);
                transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
            }
            else
            {
                // Just lookat
                transform.LookAt(target);
            }
        }
    }

    private void Start()
    {
        // Make the rigid body not change rotation
        if (GetComponent<Rigidbody>() != null)
        {
            GetComponent<Rigidbody>().freezeRotation = true;
        }
    }
}

Because of the damping if the target is moving then the camera will lag behind. So instead of looking at where the target is you should make the camera look at where the target will be.

Quaternion rotation = Quaternion.LookRotation((target.position + targetVelocity) - transform.position);

You could kill that script and use Cinemachine because that sort of behaviour needs nothing but a set up in Inspector, and you get a ton of features like dead zones, smoothing, and what not.

In any case, check where that object’s origin is. There’s no guarantee that it isn’t actually below and behind the helicopter. Or perhaps you are targeting the wrong object/transform.

Never get the same component twice! This sort of code isn’t just wasteful, it makes for very unreadable code too especially as you work with multiple such components. You have variables after all, and in this case you can use TryGetComponent:

        // Make the rigid body not change rotation
        if (TryGetComponent<Rigidbody>(out var body))
        {
            body.freezeRotation = true;
        }

I didn’t know Cinemachine. Thank you.