Camera follow player walking during sequence

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
1million_naira
Posts: 7
Joined: Sun May 05, 2024 11:37 am

Camera follow player walking during sequence

Post by 1million_naira »

Hello, how are you all doing today? I hope all is well!

I have been using the dialogue system for a few days and it has really helped me to progress my game a lot.

I want to try something where I use the MoveTo(); sequence command to move the character to a trigger game object whilst a conversation is taking place, but I want the camera to follow them (the main actor) until they reach the game object, I am wondering if there is any camera command for this. This is a 2d game and I am using orthographic camera.

Thank you,
Kind regards!
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Camera follow player walking during sequence

Post by Tony Li »

Hi,

If you were in 3D, I'd recommend using the LiveCamera() sequencer command that follows the subject, versus the Camera() sequencer command that records the destination position when the command starts and moves the camera there without following the subject. The 2D equivalent of Camera() is Zoom2D(), but there's no live (follow) camera equivalent.

Can you use Cinemachine? The Dialogue System has good Cinemachine support. If you're using the Unity 6 preview, make sure to download the Cinemachine integration patch from the Dialogue System Extras page.
1million_naira
Posts: 7
Joined: Sun May 05, 2024 11:37 am

Re: Camera follow player walking during sequence

Post by 1million_naira »

Tony Li wrote: Sun May 05, 2024 12:15 pm Hi,

If you were in 3D, I'd recommend using the LiveCamera() sequencer command that follows the subject, versus the Camera() sequencer command that records the destination position when the command starts and moves the camera there without following the subject. The 2D equivalent of Camera() is Zoom2D(), but there's no live (follow) camera equivalent.

Can you use Cinemachine? The Dialogue System has good Cinemachine support. If you're using the Unity 6 preview, make sure to download the Cinemachine integration patch from the Dialogue System Extras page.
Hello sir, thank you for your reply!

I will look into the cinemachine support now, thank you!
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Camera follow player walking during sequence

Post by Tony Li »

Glad to help!
1million_naira
Posts: 7
Joined: Sun May 05, 2024 11:37 am

Re: Camera follow player walking during sequence

Post by 1million_naira »

Hello Sir,

I did some reading and found a sequence command CinemachineTarget(), which I believes works if I set a CinemachineVirtualCamera component on the game object I want the camera to follow.

Then I add the command to a dialogue entry:

Code: Select all

CinemachineTarget(Koza, listener, follow);
AnimatorLayer(1, 1, listener, 0.5) //Increase weight of walk layer;
MoveTo(Trigger, Koza, 30); //Move character to target
However, when I run the conversation, the character walks but the camera does not follow him. I also tried CinemachinePriority() with the game object of Virtual Camera as parameter, but it also did not work.

I must be missing something,
Thank you,
Kind regards!
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Camera follow player walking during sequence

Post by Tony Li »

Hello,

The first parameter to CinemachineTarget() should be the name of the virtual camera GameObject, not the name of the subject that it will follow.

Instead of CinemachineTarget(), I recommend creating a vcam GameObject that is configured to follow Koza. Then set its Priority to 0, or whatever value is lower than your primary vcam's Priority, so your primary vcam will take precedence.

Then, in the dialogue entry's Sequence, use CinemachinePriority() to increase the follow vcam's Priority higher than your primary vcam. This will make it take precedence over the primary vcam.

For example, say your follow vcam is named "VcamFollowKoza". Set the Sequence to:

Code: Select all

CinemachinePriority(VcamFollowKoza, 999);
AnimatorLayer(1, 1, listener, 0.5);
MoveTo(Trigger, Koza, 30)->Message(Done);
CinemachinePriority(VcamFollowKoza, 0)@Message(Done);
1million_naira
Posts: 7
Joined: Sun May 05, 2024 11:37 am

Re: Camera follow player walking during sequence

Post by 1million_naira »

Tony Li wrote: Sun May 05, 2024 9:08 pm Hello,

The first parameter to CinemachineTarget() should be the name of the virtual camera GameObject, not the name of the subject that it will follow.

Instead of CinemachineTarget(), I recommend creating a vcam GameObject that is configured to follow Koza. Then set its Priority to 0, or whatever value is lower than your primary vcam's Priority, so your primary vcam will take precedence.

Then, in the dialogue entry's Sequence, use CinemachinePriority() to increase the follow vcam's Priority higher than your primary vcam. This will make it take precedence over the primary vcam.

For example, say your follow vcam is named "VcamFollowKoza". Set the Sequence to:

Code: Select all

CinemachinePriority(VcamFollowKoza, 999);
AnimatorLayer(1, 1, listener, 0.5);
MoveTo(Trigger, Koza, 30)->Message(Done);
CinemachinePriority(VcamFollowKoza, 0)@Message(Done);

Thank you sir, I have made those corrections,

What I did was create an empty game object, then add CineMachineVirtualCamera component to it, then dragged my player object into its transform field.

Then added suggested sequence commands to dialogue entry:

Code: Select all

CinemachinePriority(VcamFollowKoza, 999);
AnimatorLayer(1, 1, listener, 0.5);
MoveTo(Trigger, Koza, 30)->Message(Done);
CinemachinePriority(VcamFollowKoza, 0)@Message(Done);
However, it seems like the camera is not moving with the player, and so the player moves off screen as the trigger game object is farther away off screen.

I wanted to do it like this because the background is quite large.

Thank you!
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Camera follow player walking during sequence

Post by Tony Li »

Hi,

Assuming that vcam is taking priority (i.e., it has the highest Priority value of all vcam in the scene after using the CinemachinePriority() sequencer command), then it's a configuration issue with your vcam. Try searching up tutorial videos on YouTube, such as:

[media]]
1million_naira
Posts: 7
Joined: Sun May 05, 2024 11:37 am

Re: Camera follow player walking during sequence

Post by 1million_naira »

Tony Li wrote: Sun May 05, 2024 10:39 pm Hi,

Assuming that vcam is taking priority (i.e., it has the highest Priority value of all vcam in the scene after using the CinemachinePriority() sequencer command), then it's a configuration issue with your vcam. Try searching up tutorial videos on YouTube, such as:

[media]]
Hello Sir, this really helped me to understand Cinemachine and VCAMS more, I managed to fix the problem thanks to you!

Thank you, kind regards!
User avatar
Tony Li
Posts: 20769
Joined: Thu Jul 18, 2013 1:27 pm

Re: Camera follow player walking during sequence

Post by Tony Li »

Glad to help!
Post Reply