In this lesson, you will learn how to guide your camera along a precise, predefined trajectory using Cinemachine’s Dolly Track system.
The Concept of Rail-Based Movement
While a standard Virtual Camera follows a target’s position, a Dolly Track allows you to force the camera to move along a fixed physical path, similar to a film crew mounting a camera on a rail system. This is perfect for cinematic sequences, side-scrolling segments, or controlled environmental reveals.
To implement this, you need two components:
- The Path: Create a
CinemachinePath(orCinemachineSmoothPath) GameObject in your scene. This acts as the "rail." You can add, remove, and reposition waypoints in the Scene View to define exactly where the camera travels. - The Dolly Controller: On your Virtual Camera, set the Body property to
Tracked Dolly. Drag your path GameObject into the Path slot.
Controlling the Position
Once linked, the camera’s position is no longer determined by its own Transform, but by the Path Position (a value representing the normalized distance along the track). You can animate this value manually or drive it via code.
For example, to move the camera forward along the track through a script, you would reference the CinemachineTrackedDolly component:
using UnityEngine;
using Cinemachine;
public class DollyMover : MonoBehaviour
{
public CinemachineTrackedDolly dolly;
public float speed = 2f;
void Update()
{
// Increment the path position over time
dolly.m_PathPosition += speed * Time.deltaTime;
}
}
By adjusting the Auto Dolly setting in the component inspector, you can also have the camera automatically snap to the closest point on the track relative to your player, creating a "sliding" effect that keeps the player perfectly framed while the camera maneuvers through tight corridors. This approach ensures your camera stays strictly on its intended path, providing a professional, polished feel to your cinematic transitions.
Key Takeaway: A Cinemachine Dolly Track decouples camera movement from character input, allowing you to choreograph cinematic camera paths that move independently of the player's navigation.