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;
}

