Virtual Camera rotation not changing until the very end of the transition

I am using Unity version 2021.3.18f and CineMachine version 2.8.9.
I have my unity project switching between virtual cameras by changing their priority levels through c# script.
When the project starts running, the virtual camera it uses stays focused on a group of 3D objects (screenshot for the inspector window of this camera is attached). When an input is detected, it switches to a different virtual camera which uses a Hard Look At to focus on a particular 3D object in the scene.
I have two of these ‘hard look at’ cameras and 3 3D objects in the scene.
When switching from one of the ‘hard look at’ cameras to another I change the follow and lookAt targets as well as the offset of the camera not currently being used before switching to it. For two of the possible targets the offset is set to (0.0f,1.5f,0.0f) and for the third object the offset is set to (-1.5f,0.0f,0.0f). I think this is important because when switching from the initial camera that follows the target group to the third object the transition is perfect but if I switch from the group camera to either of the other two cameras then the camera’s rotation doesn’t change at all during the blend until it gets right above the object, at which point it snaps to the correct angle. I want to know how I can make the rotation be changed to where it needs to be over the course of the blend rather than a jump at the end.
Apologies if this is completely unreadable I’m attaching as much screenshots etc. as I can.

Here’s my basic code for switching the cameras:

void SwitchCam(string currentinput)
        {
            //assign focus object depending on input
            switch (currentinput)
            {
                case "rightAnalog":
                        focusObject = targetGroup.m_Targets[1].target;
                        offset = new Vector3(0.0f, 1.5f, 0.0f);
                    break;
                case "leftAnalog":
                        focusObject = targetGroup.m_Targets[2].target;
                        offset = new Vector3(0.0f, 1.5f, 0.0f);
                    break;
                case "a":
                        focusObject = targetGroup.m_Targets[3].target;
                        offset = new Vector3(-1.5f, 0.0f, 0.0f);
                    break;
            }
          
            if (VCam1.Priority == 11)
            {
                VCamSwitch(VCam1, VCam2, focusObject, transposer2, offset);
            }
            else if(VCam2.Priority == 11)
            {
                VCamSwitch(VCam2, VCam1, focusObject, transposer, offset);
            }
            else
            {
                VCamSwitch(ComposerCam, VCam1, focusObject, transposer, offset);
            }
        }

        //switches which VirtualCam is top priority and gives the new top priority cam a target to look at
        void VCamSwitch(CinemachineVirtualCamera currentcam, CinemachineVirtualCamera newcam, Transform target, CinemachineTransposer trans, Vector3 offset)
        {
            currentcam.Priority = 9;
            newcam.LookAt = target;
            newcam.Follow = target;
            trans.m_FollowOffset = offset;

            newcam.Priority = 11;
        }



8847232--1206031--Hierarchy.png

When you blend between vcams with different lookAt targets, the lookAt point lerps from the first position to the second. Imagine now a situation where the first lookAt point is 10m in front of the camera, and the second is 1m behind the camera. As the blend progresses, the lookAt point gets closer and closer to the camera, but the camera rotation doesn’t change until the lookAt point goes behind the camera, at which time the rotation will suddenly flip. Is that the sort of thing that’s happening?

This could be what is happening, I’m not really sure to be honest with you. The first camera’s lookAt target is a group of 3D objects and the second camera’s lookAt target is one of the 3D objects inside that group so I would have thought that the target positions shouldn’t be that different. If this is what is happening would there be any way for me to reduce the sudden change in rotation?

I’ve fixed this issue, for anyone in the future checking this page for help I’ll leave what fixed it for me here.

So the reason my blend wasn’t changing its rotation until the very end is because the original camera I was transitioning off of (let’s call it Cam1) had a LookAt target which continued to be the LookAt target for our Main Camera until the position of Cam2 had been reached, at which point Cam2 was used for the virtual camera, changing the LookAt target and subsequently rotating the camera 90 degrees.
After a long time searching online (cinemachine docs could really do with being far more detailed IMO) I found this forum post: Cinemachine blending doesn't make sense?
In it Gregory suggested to the user to try setting the LookAt Target to null for a pure rotation blend.
So I did that and set Cam1’s LookAt target to null before beginning the blend (you can keep your LookAt target up until that point) through code and my problem vanished, only smooth blends now!
My reasoning behind why this works could be completely wrong but it does work and that’s what matters most

TL;DR : Set your first camera’s LookAt to null before initiating the blend

2 Likes