3rd Person Follow, Orbital, Tracked Dolly, and Transposer in Cinemachine
Objective: Combine Body and LookAt to get beautiful camera shots!
In today’s article, we will create a scene to combine different camera styles. In the gif above, we go from 3rd person to a high elevation followed by tracked dolly and a look at and to end it back on the 3rd person.
We will need to create four different trigger’s and four virtual camera’s.
Each of the triggers have a Box Collider on them with IsTrigger set.
Each camera will need to be set up correctly. 3rd Person and Track Dolly camera will need both Lookat and Follow set, while Lookat camera will need to have Lookat assigned and follow be empty. The High Elevation camera will just need to be aligned correctly.
To use the Tracked Dolly, create a path object and add the component CinemachinePath, we talked about this in yesterdays article.
On the Tracked Dolly camera, assign the path and enable Auto Dolly.
Now it’s time to work on the logic to swap camera’s. We will create a CameraManager empty Manager and a CameraManager Script. In the script we will need a GameObject Array.
Since we will need to get the priority of the Virtual camera’s, we need to have the Cinemachine Library.
Next we will use create a public ResetAllCameras method. Inside this method we will loop through all the cameras and set the priority back to 10.
We will call this method in start.
Next, we will create another public method called, SetCamera that takes in a camera index. We will use that index to set the priority to 15.
Back in Unity we will add the script to the game object and assign the camera’s to the array.
Now we will work on checking for the player on the triggers to change cameras. Create a new script called CameraSwap. We will need two variables, one for CameraManager and one for int. The Int will let the Camera Manager know which camera to use.
In start we will assign the _cameraManager by using GameObject.Find().
Now we will use OnTriggerEnter to check for the player. If the player interacts with the trigger, we will call ResetallCameras to reset them all to 10. Following that we will call SetCamera and pass in the int.
Back in Unity, on all the triggers we will add this script to. Set the number to the associated camera in the Array. For example my 3rd Person camera is index 0 in the Array so for the 3rd Person Trigger I assign 0 in _whichCamera.
Once they are all set up, the camera’s will swap. This can be used to make an interesting scene if done correctly.
Thank you for reading and have a wonderful day!