Cinemachine POV Look At issue

Hi,

I use a virtual camera on a Tracked Dolly and POV aim.
I want to recenter the view automatically on an object (a cube), but for now the view always recenter on start orientation.
I configured my virtual camera like the bottom screen.

Can someone as a solution to recenter on the cube and not the start orientation?

Thanks for your help.

Under POV, the recenter target option’s Look At Target Forward mode is going to recenter the view, so that the camera forward is parallel and in the same direction as the Look At Target Forward.

If you’d like to recenter so that the camera is looking at the box, then you could write a script that will orient the box in a way that it’s forward is the same as the camera-box vector.

For example, like in the image here:

See the example script that will accomplish this below. To use this attach the script to your box, and add the vcam to the script. If you don’t want to visually rotate the box, you could have an invisible child gameObject and rotate and look at that instead.

using Cinemachine;
using UnityEngine;
public class RotateMeSoCameraLooksAtMe : MonoBehaviour
{
    public CinemachineVirtualCamera vcam;
    void Update()
    {
        var vcamMeVector = transform.position - vcam.transform.position;
        transform.rotation = Quaternion.LookRotation(vcamBoxVector);
    }
}

Thanks for the solution !

For others with the same issue, I just modify the script exemple to take the camera position instead of the virtual camera.

1 Like

If the solution suggested above doesn’t work for you, try this:
(CurrentlySpectatingCamera is a CinemachineVirtualCamera reference)

        /// <summary>
        /// Rotates the current camera to face
        /// </summary>
        /// <param name="target"></param>
        public void LookAt(Transform target)
        {
            var pov = CurrentlySpectatingCamera.GetCinemachineComponent<CinemachinePOV>();
            if (pov != null)
            {
                // Calculate the direction from the camera to the target
                var direction = target.position - CurrentlySpectatingCamera.transform.position;

                // Calculate the rotation to look at the target
                var rotation = Quaternion.LookRotation(direction);

                // Apply the rotation to the POV component
                pov.m_HorizontalAxis.Value = rotation.eulerAngles.y;
                pov.m_VerticalAxis.Value = rotation.eulerAngles.x;
            }
        }

I like this better as it doesn’t involve attaching a script to anything you want your camera to look at (and rotating it)