[HOWTO] How To: Use Cinemachine with the Dialogue System
Posted: Sat Jul 06, 2019 2:26 pm
This is a brief description of how to use Cinemachine with the Dialogue System. Cinemachine is a Unity feature that you can enable in Unity's Package Manager window. It provides advanced camera control.
Cinemachine uses components called Cinemachine Virtual Cameras (vcams for short) that define how the camera should work (e.g., follow targets, zoom in on a location, etc.). Each vcam has a Priority value. Cinemachine uses the vcam that has the highest Priority. Normally you'll have a vcam that controls the camera during regular gameplay, for example following the player character.
You can add another vcam to the scene that focuses on a conversation NPC. Give it a Priority of 0 so Cinemachine doesn't use it during regular play. When the conversation starts, increase its Priority to something higher than 10.
There are two ways you can control a vcam's Priority in a conversation:
1. Add a Cinemachine Priority On Dialogue Event component to the NPC. Set the dropdown to OnConversation. Assign the vcam. Configure it to increase the vcam's Priority during conversations.
2. Or use the CinemachinePriority() sequencer command.
You can use both. For example, use Cinemachine Priority On Dialogue Event to prioritize a vcam that focuses on the NPC at the start of the conversation. Say that during the conversation the NPC points to a mysterious object that she wants the player to investigate. Use CinemachinePriority() to prioritize a different vcam that focuses on the mysterious object. Later, use another CinemachinePriority() to drop the priority of the mysterious object vcam. This will cause the NPC's vcam to take effect again.
If your project pauses the game during conversations (i.e., sets Time.timeScale to zero), tick the camera's Cinemachine Brain > Ignore Time Scale checkbox. This will allow Cinemachine to keep working even if a conversation pauses the game.
Cinemachine uses components called Cinemachine Virtual Cameras (vcams for short) that define how the camera should work (e.g., follow targets, zoom in on a location, etc.). Each vcam has a Priority value. Cinemachine uses the vcam that has the highest Priority. Normally you'll have a vcam that controls the camera during regular gameplay, for example following the player character.
You can add another vcam to the scene that focuses on a conversation NPC. Give it a Priority of 0 so Cinemachine doesn't use it during regular play. When the conversation starts, increase its Priority to something higher than 10.
There are two ways you can control a vcam's Priority in a conversation:
1. Add a Cinemachine Priority On Dialogue Event component to the NPC. Set the dropdown to OnConversation. Assign the vcam. Configure it to increase the vcam's Priority during conversations.
2. Or use the CinemachinePriority() sequencer command.
You can use both. For example, use Cinemachine Priority On Dialogue Event to prioritize a vcam that focuses on the NPC at the start of the conversation. Say that during the conversation the NPC points to a mysterious object that she wants the player to investigate. Use CinemachinePriority() to prioritize a different vcam that focuses on the mysterious object. Later, use another CinemachinePriority() to drop the priority of the mysterious object vcam. This will cause the NPC's vcam to take effect again.
If your project pauses the game during conversations (i.e., sets Time.timeScale to zero), tick the camera's Cinemachine Brain > Ignore Time Scale checkbox. This will allow Cinemachine to keep working even if a conversation pauses the game.