Cinemachine is a powerful tool designed to enhance in-game cameras. It helps in creating dynamic and automated cameras, reducing the need for manual camera set ups. By simulating the real-world camera logic, Cinemachine enhances the cinematic quality and overall gameplay experience.
The Cinemachine Brain is the central controller that manages the behavior of all virtual cameras within a scene.
Key features of Cinemachine brain are given below.
Camera blending: It handles transitions between different virtual cameras.
Output control: Output control renders the final output, managing the post-processing and other visual effects.
Integration: It works seamlessly with Unity's other systems for a collaborative workflow.
Virtual cameras are individual camera set ups within Cinemachine, each of which is capable of unique attributes and behaviors.
Dynamic composition: This type of composition adjust framing and positioning to maintain the optimal composition.
Customizable properties: You can modify settings like field of view, depth of field, and much more to gain specific visual effects.
Target tracking: The camera automatically follows and frames characters or objects within the scene.
The Cinemachine brain and virtual cameras interact in the following ways.
Priority system: Virtual cameras can be assigned priorities, and the brain will switch between them based on the set rules.
Real-time adjustment: The brain responds to changes in the virtual cameras, updating the final output dynamically.
Here is a step by step guide on how to use Cinemachine.
Go to Windows > Package Manager.
Search for Cinemachine.
Install Cinemachine.
You will be able to see the Cinemachine in your project.
Go to GameObject > Cinemachine.
Click on the Main Camera.
Click on Add Component.
Search CinemachineBrainCamera.
Click to add.
Create empty object by right clicking in the hierarchy.
Click on the empty object.
Go to add component.
Search CinemachineVirtualCamera.
Click to add the component.
After adding a virtual camera, you need to configure various properties and set up the position and rotation of all the virtual cameras.
Note:
All the discussed states and properties can be found in the inspector window.
These properties are visible if you add the CinemachineVritualCamera as a component to the GameObject (as shown in the demonstration below).
Live: It controls Unity camera and it blends between virtual cameras. It acts as the only live virtual camera after
Standby: It follows target without controlling Unity camera. It has same or lower priority than live virtual camera.
Disabled: It means no control or follow and no processing power. It can control Unity camera in blends or
Solo: It makes virtual camera temporarily live for immediate feedback.
Game window guides: It shows compositional guides when using specific settings.
Save during play: This property allows for adjustments only in the play mode. No copy pasting is needed.
Priority: It determines the shot importance.
Higher value
No effect with the timeline.
Follow: This property is used to follow targets for movement; used for Unity camera's position or virtual camera's transform.
Look at: It usually targets the GameObject for aiming. It is used for Unity camera's rotation or virtual camera's orientation.
Position blending
Linear: It refers to the standard linear blend.
Spherical: It refers to the spherical blend around look at position.
Cylindrical: It refers to the cylindrical blend around look at position; vertical coordinate is linear.
Lens
Field of view: It refers to the camera view in vertical degrees.
Presets: It refers to the settings for commonly-used lenses; editable.
Orthographic size: It refers to the half-height of camera view for orthographic camera.
Near clip plane: This plane is related to the closest drawing point.
Far clip plane: This type of plane is related to the furthest drawing point.
Dutch: It is unique to virtual camera that tilts Unity camera on z-axis.
Extensions: It helps in adding extra behaviors; option to add new extensions.
Note: You can add as many virtual cameras as you like, depending on your project requirements and camera settings.
In the video below, there are two virtual cameras set up. If you disable one of the virtual camera in the play mode, you will notice how the camera blends to the second virtual camera.
Similarly, you can set up and adjust multiple cameras and control the view of your games.
The sample project has:
A camera set up as CinemachineVirtualCamera.
A main camera set up as CinemachineBrain.
Note:
As you run the project, notice how the camera changes as the player moves.
Press the arrow keys to control the player.
Press space to jump.
import React from 'react'; require('./style.css'); import ReactDOM from 'react-dom'; import App from './app.js'; ReactDOM.render( <App />, document.getElementById('root') );