In this lesson, you will learn how to script precise control over a CinemachineDollyCart to trigger camera angles or narrative events at specific milestones along a path.
While a Dolly Cart is often set to move at a constant speed, cinematic storytelling requires the ability to pause, speed up, or stop movement when your player hits specific game triggers. To do this, we manually control the m_Position property of the CinemachineDollyCart component via C#.
Manual Positioning vs. Auto-Play
By default, the Dolly Cart uses an Update Method of "Update" or "Fixed Update," which moves the cart automatically. To synchronize movement with game events, set the Update Method to "Manual" in the Inspector. This prevents the cart from moving on its own, giving your script total authority over its location on the path.
Scripting the Motion
You can now create a controller script that updates the m_Position based on your game’s requirements. Here is a simple implementation that moves the cart forward when an event occurs:
using UnityEngine;
using Cinemachine;
public class CinematicController : MonoBehaviour
{
public CinemachineDollyCart dollyCart;
public float speed = 5f;
private bool isMoving = false;
void Update()
{
if (isMoving)
{
// Move along the path manually using delta time
dollyCart.m_Position += speed * Time.deltaTime;
}
}
// Call this via a Trigger Volume or Game Event
public void StartCinematicSequence()
{
isMoving = true;
}
}
Syncing Events
Because you are now updating dollyCart.m_Position in code, you can easily check its value to trigger logic. For example, if your path has a total length of 10 units, you can check if (dollyCart.m_Position >= 9.5f) to fire off an event—like a camera transition to a different Virtual Camera or a dialogue prompt—exactly when the cart reaches the end of the track. This level of control ensures your camera work is perfectly locked to the rhythm of your gameplay events.
Key Takeaway: By setting the Dolly Cart to "Manual" update mode, you gain frame-perfect control over its path progress, allowing you to trigger game events precisely when the camera reaches specific coordinates.