Page 1 of 1

Follow target smoothly with Cinemachine

Posted: Thu Feb 24, 2022 10:43 am
by Rose
Hi there!
I'm currently working on making a Cinemachine Virtual Camera slowly pan to a character (the listener) who is off-screen during a scene.

It's working except that the camera snaps to the character immediately. And because the character is far away from where this camera is at the start, it's a little jarring. I'd like it to move to the character smoothly and gradually in a certain number of seconds.

I've tried adding the following to the Sequence:

Code: Select all

CinemachinePriority(Virtual Camera 3);
CinemachineTarget(Virtual Camera 3, listener, follow)

Code: Select all

CinemachinePriority(Virtual Camera 3);
CinemachineTarget(Virtual Camera 3, listener, follow, 5)

Code: Select all

CinemachinePriority(Virtual Camera 3);
CinemachineTarget(Virtual Camera 3, listener, follow)@5
But they all are snapping to the character immediately. Maybe I'm missing an extra thing that needs to go in the Sequence? or maybe my CinemachineVirtualCamera component is set up wrong?

Re: Follow target smoothly with Cinemachine

Posted: Thu Feb 24, 2022 11:35 am
by Tony Li
Hi,

You'll want to use CinemachinePriority() without CinemachineTarget().

When you bump up the priority of a virtual camera (vcam), Cinemachine will smoothly move from its previous position (that is, the target of the previous highest-priority vcam) to the target of the new highest-priority vcam.

On the other hand, if you change a vcam's target using CinemachineTarget(), Cinemachine doesn't have two vcams to transition between, so it jumps to the new target.

Try this: Configure a virtual camera (vcam) to follow a specific character. For example, say the character GameObject is named "Ann". Create a vcam named "Ann vcam" that follows Ann.

Then use only CinemachinePriority() to raise the priority of that vcam. Example:

Code: Select all

CinemachinePriority(Ann vcam); {{default}}
The {{default}} makes the sequence also include the Dialogue Manager's Default Sequence, if you need that. If this sequence is the Default Sequence, or if you don't want to play the Default Sequence, omit {{default}}.

You can make this more general by relying on the built-in variable "Conversant", which is the name of the conversation conversant. Example:

Code: Select all

CinemachinePriority([var=Conversant] vcam); {{default}}
When you're talking with Ann, the value of "Conversant" will be "Ann". So "[var=Conversant] vcam" will evaluate to "Ann vcam".

Remember to set the priority back down when you no longer want to follow Ann.

Also, if you want to follow the NPC at the beginning of the conversation and stop following at the end, there's a simpler way. Add a Cinemachine Priority On Dialogue Event component to the NPC. Set Trigger to OnConversation, and assign the vcam.

Re: Follow target smoothly with Cinemachine

Posted: Thu Feb 24, 2022 12:36 pm
by Rose
Ahh thank you! Followed these instructions and the camera is moving nice and smooth this way. :mrgreen:

Re: Follow target smoothly with Cinemachine

Posted: Thu Feb 24, 2022 12:53 pm
by Tony Li
Great! Glad to help.