- Open the Package Manager through “Window>Package Manager.”
- Search “Cinemachine” and click “Install.” Note:
- Add a Cinemachine Brain component to the main camera.
Transform Based Cinemachine
- First, drag the “MainCamera” into the timeline and select “Add Cinemachine Track.” Then right-click the new Cinemachine Track and select “Add Cinemachine Shot.”
- Select the new Cinemachine Shot from the timeline, and in the inspector, look for the “Virtual Camera” property then click Create, this creates a new Virtual Camera for us to use.
- After creating a new virtual camera, assign the “Kart” game object to the “Look At” property of the “Cinemachine Virtual Camera” component.
- Set the virtual camera’s position and adjust the soft zone and dead zone to your liking. Also, don’t forget to adjust the Cinemachine Shot clip’s start and end on the timeline.
- This would be the final output:
Track and Dolly
Create a new Dolley Camera with Track (Cinemachine Tracked Dolly).
- The created dolly track is a series of waypoints for the virtual camera to move between. To create a new waypoint, click on the plus button on the inspector.
To create a path for the virtual camera, we can adjust the waypoints in the scene view that will automatically update the waypoint’s transform in the inspector.
We can adjust the position of our camera along the path between waypoints by selecting our camera and adjusting the value of Path Position in the inspector. Each integer value represents the position of a waypoint on the track.
(Ex: 0 = 0 waypoint, 1 = 1 waypoint)
5. We can then record and animate the Path Position value by assigning the virtual camera to an animation track in the timeline.
- We can also use track and dolly to track and transform automatically. This is useful when following a player along the path. To do this, we must assign the Kart to the Follow property of the camera and enable the Auto Dolly Setting.
As you can see, the camera follows the player whenever the player moves back and forth. But, when the player moved far away from the track, the camera stopped at the last waypoint.
- If you want to add another shot from another track and dolly camera, we can assign different virtual cameras to each clip in a new cinemachine track.
Create a new Cinemachine State-Driven Camera (Cinemachine State-Driven).
The virtual camera children's property in the inspector lists all the virtual cameras that our state-driven camera is going to use. You can add existing virtual cameras by assigning it as a child of the State Driven camera.
After setting up the shots on each of our virtual cameras, we can now set up our states. Any animator component in our scene can trigger states. First, assign the animator on the Animated Target property.
We can then add new States and assign them to their respective cameras.
- You can adjust the number of seconds to wait before entering a state by changing the value of Wait.
- You can change the default blend setting from the list, or you can create a custom blend asset to customize the blend for different states.
Create a new Cinemachine Free Look Camera (Cinemachine Free Look).
You can then assign the transform for the "Follow" and "Look at" property.
In the scene view, you can see three circles generated around the player character. They represent the orbit for the three camera rigs (TopRig, MiddleRig, and BottomRig).
- You can enable/disable the Invert on the X and Y-Axis.
- You can change how high and wide each camera rig’s orbit by adjusting their height and radius.
- You can change how the camera transition between points by adjusting the Spline Curvature value. A lower value creates a linear transition, and a higher value creates a much more curve transition.
- You can also enable to use of the Common Lens property, which applies the lens settings to all three child rigs. Otherwise, child rig settings will be applied.
- Create a new Cinemachine ClearShot Camera (Cinemachine ClearShot).
Cinemachine automatically adds a new virtual camera as a child of Cinemachine ClearShot camera. You can add existing virtual cameras by assigning it as a child of the ClearShot camera.
On the parent, assign which object to track, by setting the transform of the "Look At" property.
Check if the child camera has a Cinemachine Collider component. This helps in assessing the quality of shots.
- Set a value for the child’s Optimal Target Distance. If greater than zero, a higher score will be given to shots when the target is closer to this distance. You can experiment with this value to get optimal results.
Import Post Processing V2 Adapter Asset Package.
On your Main Camera, add a Post-process Layer component
- Set the layer of the Main Camera to a custom layer named PostProcessing.
- Also, set the Volume blending Layer to PostProcessing.
- You can create a default post-process globally on all virtual cameras by adding a post-process volume component on our main camera and enabling Is Global property.
You can then create a new Post-Process Volume profile by clicking New and add different post-process effects you want to take effect globally.
You can also add a post-process override by adding a CinemachinePostProcessing extension on a virtual camera. This allows us to add more effects while the global post-process is also taking effect.
- If you like to blend between different post-processing effects, we can use post-processing volume.
- The blend distance blends the current post-process to the post-process applied to the volume as it enters the area. A value of 0 means there will be no blending, and the volume overrides will be applied immediately upon entry to the attached collider.
- We can also use clip blending in the timeline to transition between post-processes; to do this, we can duplicate the camera you want to work with. Then on the duplicate camera clone, select the cinemachine post-process profile then add the effects you want to take effect after the transition.
* Changed the focus of the camera on a much closer range.
- When we are Tracking a target (Look At) and using a Depth of Field effect, we can enable the Focus Tracks Target that dynamically pulls focus on our target based on its distance from the camera.
Create a new Cinemachine 2D Camera (Cinemachine Virtual Camera).
Assign the “Player” prefab to the “Look At” and “Follow” property.
Adjust the Soft Zone and Dead Zone.
Add a Cinemachine Confiner component.
Create a “GameObject” with a “PolygonCollider 2D” component. Edit the collider and set it to your desired size and position. Also, don’t forget to set it to “IsTrigger.”
- Assign the created “GameObject” with “PolygonCollider2D” to the Virtual Camera’s Cinemachine Confine Component: “Bounding Shape 2D” property.
This would be the final output.
You can notice that when the player leaves the dead zone and goes toward the soft zone, the camera starts tracking the player and moves in that direction.
This is the central Cinemachine component that does all the magic. It's a component attached to the Unity camera, and it monitors all the Virtual Cameras in the scene and drives the Unity camera using the shot it likes best.
What happens is that there is only one Unity Camera. The brain that gets installed on it is responsible for positioning and configuring that one camera to be in the right place at the right time, according to the instructions provided by the virtual cameras that the brain is observing.Cinemachine Virtual Camera
This component is intended to be attached to an empty Transform GameObject, and it represents a Virtual Camera within the Unity scene.
The Virtual Camera will animate its Transform according to the rules contained in its CinemachineComponent pipeline (Aim, Body, and Noise). When the virtual camera is Live, the Unity camera will assume the position and orientation of the virtual camera.
A virtual camera is not a camera. Instead, it can be thought of as a camera controller, not unlike a cameraman. It can drive the Unity Camera and control its position, orientation, lens settings, and PostProcessing effects. Each Virtual Camera owns its own Cinemachine Component Pipeline, through which you provide the instructions for dynamically tracking specific game objects.
A virtual camera is very lightweight and does no rendering of its own. It merely tracks interesting GameObjects and positions itself accordingly. A typical game can have dozens of virtual cameras, each set up to follow a particular character or capture a particular event.
A Virtual Camera can be in any of three states:
- Live: The virtual camera is actively controlling the Unity Camera. The virtual camera is tracking its targets and being updated every frame.
- Standby: The virtual camera is tracking its targets and being updated every frame, but no Unity Camera is actively being controlled by it. Standby is the state of a virtual camera that is enabled in the scene, but at a lower priority than the Live virtual camera.
- Disabled: The virtual camera is present but disabled in the scene. It is not actively tracking its targets, and so consumes no processing power. However, the virtual camera can be made live from the Timeline.
The Unity Camera can be driven by any virtual camera in the scene. The game logic can choose the virtual camera to make live by manipulating the virtual cameras' enabled flags and their priorities, based on game logic.
To be driven by a virtual camera, the Unity Camera must have a CinemachineBrain behavior assigned to it. This behavior will select the most eligible virtual camera based on its priority or other criteria, and manages blending.
The object that the camera wants to look at (the Aim target). If this is null, then the vcam's Transform orientation will define the camera's orientation.
The object that the camera wants to move with (the Body target). If this is null, then the vcam's Transform position will define the camera's position.
Cinemachine Tracked Dolly
A Cinemachine Virtual Camera Body component that constrains camera motion to a CinemachinePath or a CinemachineSmoothPath. The camera can move along the path.
This component can operate in two modes: manual positioning and Auto-Dolly positioning. In Manual mode, the camera's position is specified by animating the Path Position field. In Auto-Dolly mode, the Path Position field is animated automatically every frame by finding the position on the path that's closest to the virtual camera's Follow target.
This is a virtual camera "manager" that owns and manages a collection of child Virtual Cameras. These child vcams are mapped to individual states in an animation state machine, allowing you to associate specific vcams to specific animation states. When that state is active in the state machine, then the associated camera will be activated.
You can define custom blends and transitions between child cameras.
To use this behavior, you must have an animated target (i.e., an object animated with a state machine) to drive the behavior.
Cinemachine Free Look
A Cinemachine Camera geared towards a 3rd person camera experience. The camera orbits around its subject with three separate camera rigs defining rings around the target. Each rig has its radius, height offset, composer, and lens settings. Depending on the camera's position along the spline connecting these three rigs, these settings are interpolated to give the final camera position and state.
Player input is supplied along two axes: the X-axis, which controls the orbital position (see CinemachineOrbitalTransposer), and the Y-axis, which controls the vertical position on the spline connecting the three child rigs.
Each child rig can have its Lens settings, or commonly shared values can be used. Additionally, each child rig can have its Composer and Noise settings.
Cinemachine Clear Shot
Cinemachine ClearShot is a "manager camera" that owns and manages a set of Virtual Camera gameObject children. When Live, the ClearShot will check the children, and choose the one with the best quality shot and make it Live.
This can be a very powerful tool. If the child cameras have CinemachineCollider extensions, they will analyze the scene for target obstructions, optimal target distance, and other items, and report their assessment of shot quality back to the ClearShot parent, who will then choose the best one. You can use this to set up complex multi-camera coverage of a scene and be assured that a clear shot of the target will always be available.
If multiple child cameras have the same shot quality, the one with the highest priority will be chosen.
You can also define custom blends between the ClearShot children.
As a component on the Virtual Camera, it holds a Post-Processing Profile asset that will be applied to the camera whenever the Virtual camera is live. It also has the optional functionality of animating the Focus Distance and DepthOfField properties of the Camera State and applying them to the current Post-Processing profile.
An add-on module for Cinemachine Virtual Camera that post-processes the final position of the virtual camera. Based on the supplied settings, the Collider will attempt to preserve the line of sight with the LookAt target of the virtual camera by moving away from objects that will obstruct the view.
Additionally, the Collider can be used to assess the shot quality and report this as a field in the camera State.
Tune these to define where you want the subject to be on-screen. These controls are incredibly versatile. The blue areas are the 'squishy' areas based on how much horizontal/vertical damping you have, and the red areas define the 'no pass' limits where the camera will always track the subject. Opening up the soft areas to create a 'dead zone' in the middle allows you to make areas of the screen immune to target motion, handy for things like animation cycles where you don't want the camera to track the target if it moves just a little.
Dead Zone Width
The camera will not rotate horizontally if the target is within this range of the position.
Dead Zone Height
The camera will not rotate vertically if the target is within this range of the position.
Soft Zone Width
When a target is within this region, the camera will gradually rotate horizontally to re-align towards the desired position, depending on the damping speed.
Soft Zone Height
When a target is within this region, the camera will gradually rotate vertically to re-align towards the desired position, depending on the damping speed.
An add-on module for Cinemachine Virtual Camera that post-processes the final position of the virtual camera. It will confine the virtual camera's position to the volume specified in the Bounding Volume field.
This is less resource-intensive than CinemachineCollider, but it does not perform a shot evaluation.
The Confiner can operate in 2D or 3D mode. The mode will influence the kind of bounding shape it will accept. In 3D mode, the camera's position in 3D will be confined to the volume. This will work for 2D games, but you will have to take the depth into account. In 2D mode, you don't have to worry about depth.
If your camera is orthographic, there will be an additional option to confine the screen edges, not just the camera point. This ensures that the entire screen area stays within the bounding shape.