I’m looking for the best practice on handling Cinemachine cameras and confining them to certain areas. I have a 3D topdown game and the player is walking between three rooms, eventually there will be a significant number more. I have two possible directions and curious what is best.
Option 1:
Create a Cinemachine Camera per room that has a Confiner3D and then set the camera priority using a Volume that increases the priority of the camera for that area.
Option 2:
Have a single cinemachine Camera and then set via code the Bounding Volume on trigger of which mesh collider to use. And on exit, set to null and disable the confiner.
For the rooms, ultimately I’m expecting them to be pre-fabs, so adding a camera once and setting it up is straight forward, but this also works with the option 2.
I’m leaning to option 2 right now to reduce the number of cameras.
Why do you want to reduce the number of cameras?
No real specific reason, other than figuring out the best way of doing it all.
One thing is that that I have only my Player object is a script that controls the cameras. Specifically it does two things, one is the move the camera above the player by modifying the Pan Tilt object on the camera. The other is that it modifies the camera offset using the Right analog stick so you can move the camera position relative around the character.
I could possible use the Cinemachine Brain Camera Activated event and pass the active camera to my player camera controller script and then just use option 1 and have a camera in each room that is triggered on entering.
You can set up each Cinemachine camera in each room to have its own mouse controls for orbiting, and leave your player script to control only the player’s motion (it could use the main Camera’s rotation as a reference frame for the input, quite independently of any Cinemachine camera).
When the player enters a room that has its own Cinemachine Camera, you just need to activate that camera and it will take over. When the player enters a new room, activate its camera and deactivate the previous one. Use the blend settings in the brain to control how the transfer happens.