Using Cinemachine
Using Cinemachine requires a new way of thinking about working with cameras. For example, you might have invested heavily in carefully scripted camera behaviors. However, Cinemachine can give the same results, if not better, in less time.
Cinemachine Cameras
Cinemachine does not create new cameras. Instead, it directs a single Unity camera for multiple shots. You compose these shots with CinemachineCameras (also referred to sometimes as Virtual Cameras). CinemachineCameras move and rotate the Unity camera and control its settings.
The CinemachineCameras are separate GameObjects from the Unity Camera, and behave independently. They are not nested within each other. For example, a Scene might look like this:
The main tasks that the CinemachineCamera does for you:
- Positions the Unity camera in the Scene.
- Aims the Unity camera at something.
- Adds procedural noise to the Unity camera. Noise simulates things like hand-held effects or vehicle shakes.
Cinemachine encourages you to create many CinemachineCameras. The CinemachineCamera is designed to consume little processing power. If your Scene is performance-sensitive, deactivate all but the essential CinemachineCameras at any given moment for best performance.
It is recommended that you use a single CinemachineCamera for a single shot. Take advantage of this to create dramatic or subtle cuts or blends. Examples:
For a cutscene where two characters exchange dialog, use three CinemachineCameras: one camera for a mid-shot of both characters, and separate CinemachineCameras for a close-up of each character. Use Timeline to synchronize audio with the CinemachineCameras.
Duplicate an existing CinemachineCamera so that both CinemachineCameras are in the same position in the Scene. For the second CinemachineCamera, change the FOV or composition. When a player enters a trigger volume, Cinemachine blends from the first to the second CinemachineCamera to emphasize a change in action.
One CinemachineCamera has control of the Unity camera at any point in time. This is the live CinemachineCamera. The exception to this rule is when a blend occurs from one CinemachineCamera to the next. During the blend, both CinemachineCameras are live.
Cinemachine Brain
The Cinemachine Brain is a component in the Unity Camera itself. The Cinemachine Brain monitors all active CinemachineCameras in the Scene. To specify the next live CinemachineCamera, you activate or deactivate the desired CinemachineCamera's game object. Cinemachine Brain then chooses the most recently activated CinemachineCamera with the same or higher priority as the live CinemachineCamera. It performs a cut or blend between the previous and new CinemachineCameras.
Tip: Use Cinemachine Brain to respond to dynamic game events in real time. It allows your game logic to control the camera by manipulating priorities. This is particularly useful for live gameplay, where action isn’t always predictable. Use Timeline to choreograph cameras in predictable situations, like cutscenes. Timeline overrides the Cinemachine Brain priority system to give you precise, to-the-frame camera control.
Positioning and Aiming
Use the Position Control properties in a CinemachineCamera to specify how to move it in the Scene. Use the Rotation Control properties to specify how to aim it.
By default, a CinemachineCamera has a single Tracking Target, which is used for two purposes:
- It specifies a GameObject for the CinemachineCamera to move with (position control).
- It specifies the LookAt target, that is the GameObject to aim at (rotation control).
If you want to use two different GameObjects for these purposes, that is done by enabling the Separate LookAt Target option in the CinemachineCamera's inspector:
Cinemachine includes a variety of procedural algorithms to control positioning and aiming. Each algorithm solves a specific problem, and exposes properties to customize the algorithm for your specific needs. Cinemachine implements these algorithms as CinemachineComponent
objects. Use the CinemachineComponentBase
class to implement a custom moving or aiming behavior.
The Position Control properties offer the following procedural algorithms for moving the CinemachineCamera in a Scene:
- Tracking: Move in a fixed relationship to the Tracking target, with optional damping.
- Position Composer: Move in a fixed screen-space relationship to the Tracking target, with optional damping.
- Orbital Follow: Move in a variable relationship to the Tracking target, optionally controlled by player input.
- Spline Dolly: Move along a predefined Spline path.
- Hard Lock to Target: Use the same position and as the Tracking target.
- Third Person Follow: Place the camera on a configurable rigid rig attached to the Tracking target. The rig rotates with the target. This is useful for TPS and POV cameras.
- Do Nothing: Do not procedurally move the CinemachineCamera. Position is controlled directly by the CinemachineCamera's transform, which can be controlled by a custom script.
The Rotation Control properties offer the following procedural algorithms for rotating a CinemachineCamera to face the Look At target:
- Rotation Composer: Keep the Look At target in the camera frame, with compositional constraints.
- Pan Tilt: Rotate the CinemachineCamera based on the user’s input.
- Same As Follow Target: Set the camera’s rotation to the rotation of the Tracking target.
- Hard Look At: Keep the Look At target in the center of the camera frame.
- Do Nothing: Do not procedurally rotate the CinemachineCamera. Rotation is controlled directly by the CinemachineCamera's transform, which can be controlled by a custom script.
Composing a shot
The Position Composer and Rotation Composer algorithms define areas in the camera frame for you to compose a shot:
Dead zone: The area of the frame in which Cinemachine keeps the target. The target can move within this region and the CinemachineCamera will not adjust to reframe it until the target leaves the dead zone.
Soft zone: If the target enters this region of the frame, the camera will adjust to put it back in the dead zone. It will do this slowly or quickly, according to the time specified in the Damping settings.
Screen Position: The screen position of the center of the dead zone. 0 is the center of the screen, +1 and -1 are the edges.
Damping: Simulates the lag that a real camera operator introduces while operating a heavy physical camera. Damping specifies how quickly or slowly the camera reacts when the target enters the soft zone while the camera tracks the target. Use small numbers to simulate a more responsive camera, rapidly moving or aiming the camera to keep the target in the dead zone. Larger numbers simulate heavier cameras, The larger the value, the more Cinemachine allows the target to traverse the soft zone.
The Game View Guides gives an interactive, visual indication of these areas. The guides appear as tinted areas in the Game view.
The clear area indicates the dead zone. The blue-tinted area indicates the soft zone. The Screen Position is the center of the Dead Zone. The red-tinted area indicates the no pass area, which the camera prevents the target from entering. The yellow square indicates the target itself.
Adjust these areas to get a wide range of camera behaviors. To do this, drag their edges in the Game view or edit their properties in the Inspector window. For example, use a larger soft zone for a fast-moving target, or enlarge dead zone to create an area in the middle of the camera frame that is immune to target motion. Use this feature for things like animation cycles, where you don’t want the camera to track the target if it moves just a little.
Using noise to simulate camera shake
Real-world physical cameras are often heavy and cumbersome. They are hand-held by the camera operator or mounted on unstable objects like moving vehicles. Use Noise properties to simulate these real-world qualities for cinematic effect. For example, you could add a camera shake when following a running character to immerse the player in the action.
At each frame update, Cinemachine adds noise separately from the movement of the camera to follow a target. Noise does not influence the camera’s position in future frames. This separation ensures that properties like damping behave as expected.