In this lesson, you will learn how to automate seamless camera transitions by linking your character's Animator states directly to specific Cinemachine Virtual Cameras.
The Concept of State-Driven Cameras
Instead of manually managing camera priorities through code or triggers, the CinemachineStateDrivenCamera component acts as a bridge between your Animator and your cameras. It monitors a specific Animator component, and whenever the character enters a specific state (like "Idle," "Run," or "Aim"), the system automatically switches to the camera associated with that state.
Setting Up the Link
To get this working, follow these steps in your scene:
- Create a Cinemachine State-Driven Camera from the GameObject menu.
- In the component's inspector, assign your character’s Animator to the "Animated Target" field.
- In the "Children" section, you will see a list of states. Drag your existing Virtual Cameras into the child slots of the State-Driven Camera object.
- For each Virtual Camera, select the specific State Name (from your Animator controller) that should trigger it.
Once configured, the State-Driven Camera watches the Animator. When a state transition occurs—for example, moving from a Locomotion state to a Combat state—the State-Driven Camera automatically performs a smooth blend to the camera assigned to that Combat state.
Controlling the Blend
Because this is a standard Cinemachine brain interaction, you don't need to write manual logic to handle the transition. You can define the Default Blend curve directly on the State-Driven Camera component. This allows you to set a Ease In Out duration for all transitions, ensuring that your camera never "snaps" abruptly when the character starts an animation.
// You don't need manual logic, but you can control the Animator
// that the State-Driven Camera is observing:
animator.SetBool("isAiming", true);
// The State-Driven Camera detects the change to the 'Aim' state
// and automatically initiates the transition to the assigned camera.
By offloading camera logic to the state machine, you keep your code clean and ensure your camera composition always matches your character's current gameplay state.
Key Takeaway: The Cinemachine State-Driven Camera eliminates manual switching logic by creating a direct, automated pipeline between your Animator's state transitions and your camera viewpoint changes.