How to use a Dolly Track in Unity
Overview
Dolly Tracks can help us smoothly and precisely move virtual cameras along a desired path. This can be great for creating some trickier camera movements, such as a camera which circles around one of the actors in our scene. In this case, while the VirtualCamera’s ‘Look At’ variable can keep the camera focused on the actor, the dolly track will let us take care of the camera’s movements (in combination with the animator and/or Timeline).
Implementation
To create a Dolly Track in Unity, ensure the Cinemachine package is installed, then click on the Cinemachine tab followed by ‘Create Dolly Camera with Track’.
This will create a DollyTrack object within your scene as well as a VirtualCamera ready to use it. Feel free to delete this virtual camera if there’s already one you want to use; just make sure that the virtual camera’s ‘Body’ enum is set to ‘Tracked Dolly’, then set the Path variable to the newly-created DollyTrack. The ‘Path Position’ variable on this component is what we’ll be using to control the camera’s position along this track.
On the DollyTrack, expand PathDetails and click the plus icon to add new positions or ‘waypoints’ to the track. We can then select and position these within our scene to get the kind of path we want. These use zero-based numbering, meaning index 0 will be the first element in the sequence/path. Back over in the PathPosition variable, we can specify which element we want our VirtualCamera to be located at (e.g. waypoint ‘2’) and can even position our camera between these elements (e.g. path position ‘2.5' to position the camera between the 2nd and 3rd waypoint).
This path position variable is especially useful for what we want to achieve, as we can use this in either the Animation dope sheet or in the Timeline when creating our keyframes. If we hit record in either of these, specify a position in the timeline/animation, then change the value of the PathPosition (and do this a couple of times), then we can end up with a VirtualCamera that will move smoothly along this path over time 😉