# 4. SplineAnimate Dollies and Cameras Part of [[Splines]]. Prev: [[3. Evaluate and Placement]]. Next: [[5. Worked Example Patrol Dolly and Posts]]. ## 4.1 SplineAnimate Add **Spline Animate** to a GameObject you want to travel the path (`UnityEngine.Splines.SplineAnimate`). In the Inspector (2.9; confirm labels): - The **Spline Container** (and spline index if the container has more than one). - **Duration** or **Speed** - one is derived from the other depending on the mode the component offers. - **Alignment** - whether the object orients to the tangent / up vector. - **Easing** and **Looping** (loop, once, ping-pong - use the enum the Inspector shows). - Play on awake, or start from script. Runtime API (2.9 family, confirmed names): `Play()`, `Pause()`, `Restart()`. Hook those from a trigger, a Timeline signal, or a boss phase ([[Boss Battles with Phases]]) rather than polling `t` unless you need it. ```csharp using UnityEngine; using UnityEngine.Splines; /// <summary>Starts a dolly when something enters a trigger. NOT compiled in Unity.</summary> public sealed class DollyGate : MonoBehaviour { [SerializeField] SplineAnimate animate; [SerializeField] string playerTag = "Player"; void Reset() => animate = GetComponent<SplineAnimate>(); void OnTriggerEnter(Collider other) { if (animate == null || !other.CompareTag(playerTag)) return; animate.Restart(); animate.Play(); } } ``` ## 4.2 Patrols Put `SplineAnimate` on an NPC root, **closed** spline, loop mode, no easing (or a mild ease if the design wants a pause at a corner - better: pause with `Pause()` at authored `t` values). Keep *behavior* in your AI ([[Enemy AI State Machine]]): the spline is the path, not the brain. When the player is spotted, `Pause()` the animate and hand control to a chase state; `Play()` when you return to patrol (consider `Restart` only if the loop should reset). A 2D platformer can still use a 3D spline in the XY plane - lock Z, or use a planar spline. ## 4.3 Camera dollies **Do not invent a Cinemachine spline-body component name.** Unless you have confirmed a spline dolly / spline cart body in *your* Cinemachine **3.1.x** documentation, do this: 1. Empty GameObject **DollyCart** with `SplineAnimate`, alignment on, duration set to the shot length. 2. A Cinemachine camera that **follows / looks at** the cart (or a child offset on the cart), using the follow / transposer body you already know from [[Cinemachine 3]] / [[2.Body Aim Noise and Priorities]]. 3. Start the animate when the shot starts (Timeline or `Play()`). That split stays official even if Cinemachine later ships a first-party spline body: the path is still a `SplineContainer`. ## 4.4 Moving platforms A platform on `SplineAnimate` that the player can stand on needs a **kinematic Rigidbody** (3D or 2D) so the physics engine can move the rider. Animating a static collider's transform is the same old platforming trap as in [[Physics 3D]]. ## 4.5 Exercise Drive a cube around the closed courtyard spline with `SplineAnimate`. Then parent a small offset to the cube and have a Cinemachine camera follow that offset for a 5-second tour of a weenie. ## Sources - `SplineAnimate`: https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.Splines.SplineAnimate.html - [[Cinemachine 3]]