Overview
"I want the camera to follow my character..." "I want to smoothly switch between multiple cameras..." "I want to implement camera shake..."
This is where Cinemachine comes in. Cinemachine is Unity's official package for camera control. It enables high-quality camera work without writing any scripts.
Tested with: Unity 2022.3 LTS / Unity 6, Cinemachine 3.x
Version note: This article covers Cinemachine 3.x. Component names and APIs differ in Cinemachine 2.x (e.g.,
CinemachineVirtualCamerahas becomeCinemachineCamera). Please check your project's version.
Installation
Cinemachine can be installed from the Package Manager.
- From the Unity Editor menu, select "Window" > "Package Manager"
- Select "Unity Registry" from the dropdown menu in the upper left
- Find "Cinemachine" in the list and click on it
- Click the "Install" button in the lower right
Core Concepts
Virtual Camera
A Virtual Camera is a virtual camera placed in the scene. It does not render anything itself; instead, it sends position and orientation data to the Main Camera's Cinemachine Brain.
A Virtual Camera consists of three main elements:
| Element | Description |
|---|---|
| Body | Controls camera position (tracking, path movement, etc.) |
| Aim | Controls camera direction (look-at, screen composition, etc.) |
| Noise | Adds camera shake and handheld effects |
Cinemachine Brain
Cinemachine Brain is a component attached to the Main Camera. It manages all Virtual Cameras in the scene and determines which Virtual Camera should be active.
Virtual Camera Basics
Creating a Virtual Camera
- Right-click in the Hierarchy window
- Select "Cinemachine" > "Cinemachine Camera"
Setting Targets
| Target | Description |
|---|---|
| Tracking Target | The target the camera follows (affects Body settings) |
| Look At Target | The target the camera looks at (affects Aim settings) |
Main Body Types
| Type | Use Case |
|---|---|
| Do Nothing | Fixed position |
| Follow | Follow a target (for 3D games) |
| Position Composer | Position the target at a specific screen location (for 2D games) |
| Orbital Follow | Orbit around a target |
| Third Person Follow | TPS-style over-the-shoulder camera |
| Spline Dolly | Move along a path |
Third Person Follow (TPS Camera)
The most commonly used camera type in TPS games. It positions the camera over the player's shoulder with aiming support.
- Create a Cinemachine Camera
- Set Body to "Third Person Follow"
- Adjust parameters:
- Shoulder Offset: Offset from the shoulder (e.g., 0.5, 0, 0 for over the right shoulder)
- Camera Distance: Distance from the player
- Damping: Smoothness of follow
Changes from Cinemachine 2.x: In 2.x, these were named
Framing TransposerandTransposer, which have been renamed toPosition ComposerandFollowin 3.x.
Practical Examples
Example 1: Camera Following a Character
- Create a Cinemachine Camera
- Configure the following:
- Tracking Target: The character's Transform
- Look At Target: The character's Transform
- Body: Follow
- Follow Offset: (0, 2, -5)
- Aim: Composer
Example 2: Smoothly Switching Between Multiple Cameras
using UnityEngine;
using Unity.Cinemachine;
public class CameraSwitcher : MonoBehaviour
{
[SerializeField] private CinemachineCamera camera1;
[SerializeField] private CinemachineCamera camera2;
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
camera1.Priority.Value = 15;
camera2.Priority.Value = 5;
}
else if (Input.GetKeyDown(KeyCode.Alpha2))
{
camera1.Priority.Value = 5;
camera2.Priority.Value = 15;
}
}
}
Example 3: Implementing Camera Shake
- Select the Virtual Camera
- Select "Add Extension" > "Cinemachine Basic Multi Channel Perlin"
- Set the Noise Profile (important):
- Click the circle button to the right of the "Noise Profile" field
- Select a preset like "6D Shake" (shake will not work without a Noise Profile)
- Set parameters:
- Amplitude Gain: 1.0 (intensity)
- Frequency Gain: 1.0 (frequency)
Important: Without a Noise Profile set, changing Amplitude or Frequency will have no effect. Use one of Unity's built-in presets like "6D Shake" or "Handheld_normal_mild", or create your own NoiseSettings asset.
using UnityEngine;
using Unity.Cinemachine;
public class CameraShake : MonoBehaviour
{
[SerializeField] private CinemachineCamera virtualCamera;
private CinemachineBasicMultiChannelPerlin noise;
void Awake()
{
// Get the noise component from the extension
noise = virtualCamera.GetComponent<CinemachineBasicMultiChannelPerlin>();
}
public void Shake(float amplitude, float frequency, float duration)
{
if (noise == null) return;
noise.AmplitudeGain = amplitude;
noise.FrequencyGain = frequency;
Invoke(nameof(StopShake), duration);
}
void StopShake()
{
noise.AmplitudeGain = 0f;
noise.FrequencyGain = 0f;
}
}
Example 4: Camera Obstacle Avoidance
- Select the Virtual Camera
- Select "Add Extension" > "Cinemachine Deoccluder"
- Set the obstacle layers in "Collide Against"
Input System Integration
To implement player-driven camera rotation with Orbital Follow or Third Person Follow, use CinemachineInputAxisController.
Setup Steps
- Add "Add Component" > "Cinemachine Input Axis Controller" to the Virtual Camera
- Create an Input Actions asset and set up a Look (Vector2) action
- Assign it to the CinemachineInputAxisController's "Input Action"
Code Example (When Controlling via Script)
using UnityEngine;
using UnityEngine.InputSystem;
using Unity.Cinemachine;
public class CameraLookController : MonoBehaviour
{
[SerializeField] private CinemachineCamera virtualCamera;
[SerializeField] private InputActionReference lookAction;
private CinemachineOrbitalFollow orbitalFollow;
void Awake()
{
orbitalFollow = virtualCamera.GetComponent<CinemachineOrbitalFollow>();
}
void OnEnable() => lookAction.action.Enable();
void OnDisable() => lookAction.action.Disable();
void Update()
{
Vector2 lookInput = lookAction.action.ReadValue<Vector2>();
// Update the horizontal rotation of Orbital Follow
orbitalFollow.HorizontalAxis.Value += lookInput.x * Time.deltaTime * 100f;
}
}
Note: When using the New Input System, make sure to enable the Input System Package in Project Settings.
Extensions
| Extension | Use Case |
|---|---|
| Cinemachine Deoccluder | Move the camera to avoid obstacles |
| Cinemachine Basic Multi Channel Perlin | Continuous camera shake (handheld, vibration) |
| Cinemachine Impulse Source | Momentary camera shake (explosions, hits) |
| Cinemachine Follow Zoom | Adjust FOV based on distance |
| Cinemachine Confiner 2D/3D | Restrict camera to a defined area |
Impulse Source (Momentary Shake)
The Impulse System is ideal for momentary camera shake on explosions or damage.
using UnityEngine;
using Unity.Cinemachine;
public class ExplosionShake : MonoBehaviour
{
[SerializeField] private CinemachineImpulseSource impulseSource;
public void Explode()
{
// Generate impulse from the explosion position
impulseSource.GenerateImpulse();
}
}
- Add "Cinemachine Impulse Source" to an empty GameObject
- Add "Cinemachine Impulse Listener" to the Virtual Camera
- Call
GenerateImpulse()from a script
Timeline Integration
Combining Cinemachine with Timeline makes it easy to create cutscenes and event sequences.
- Open the Timeline window (Window > Sequencing > Timeline)
- Add a Cinemachine Track to the Timeline
- Drag and drop multiple Virtual Cameras onto the Cinemachine Track
- Adjust the placement and duration of each Virtual Camera
Best Practices
- Use consistent naming for Virtual Cameras - e.g., "VCam_Follow", "VCam_Boss"
- Set Priority values strategically - Use increments of 10 to leave room for inserting new cameras
- Adjust Damping for smoothness - Use smaller values for action games, larger values for adventure games
- Tune Blend Time - Typically 1-2 seconds feels natural
- Leverage Extensions - Obstacle avoidance, camera shake, area confinement, and more
Summary
Cinemachine is a powerful tool for controlling cameras in Unity.
- Implement camera work without scripting - Just configure settings in the Inspector
- Automatically adapts to animation and terrain changes - No manual adjustments needed
- Achieve high-quality camera work quickly - Follow, switch, shake, obstacle avoidance
- Create cinematic sequences with Timeline integration - Cutscenes and event sequences
Start using Cinemachine to create cinematic camera work in your projects.