Virtual Cameras w/ Cinemachine in Unity 2020 — Part 2
Let’s create a new folder for our Animations, create an Animation called Cube_Movement, and add it to our cube.
We’ll set our animation to loop.
Select the Cube in the Hierarchy window and open the Animation window.
Scroll out the Animation window until you can see five seconds.
Click the record button and add a few keys over time with the cube moving as desired.
To add a key to our animation, while in record mode, click on a number such as 1 second.
Move the cube to the desired location.
A key will appear.
Rinse and repeat for each desired position.
If you want it to smoothly transition from last frame to first frame, copy paste the Transform component of the cube at the start and paste it into the cube’s transform component on the last frame.
Unclick record and hit play to review the entire animation looping.
Adjust as needed.
Virtual Cameras with an Animated Look At Target
Let’s drag and drop our Cube that we just animated onto our vcam1’s Look At field.
I’ve added some blue spheres in the background so that the scene has some reference points for the movement occurring.
As we can see, the Look At is working properly and following our cube.
VCam Aim Settings
Aim is useful for rotating our virtual camera, whereas the body settings are for changing the VCam’s position.
Aim (Composer) Settings
This Virtual Camera Aim algorithm rotates the camera to face the Look At target. It also applies offsets, damping, and…
The first setting on our VCam > Aim (Composer) component is Tracked Object Offset.
This is very straight forward, it just sets an offset for the camera view as desired.
Aim Composer (Lookahead Time)
“The algorithm estimates the point that the target will be this many seconds into the future.”
This setting tells the VCam to look at the target’s animation and actually lead the target’s position with the VCam.
We can further adjust this behavior with the Lookahead Smoothing and Lookahead Ignore Y settings.
The Lookahead Ignore Y setting will lock the camera in the vertical axis so that the camera is never adjusted to look up or down while Aiming at a target.
This can be very useful for games that have a top-down perspective.
Aim Composer (Damping) Settings
“How responsively the camera follows the target in the screen-horizontal direction.”
Or vertical direction in the case of Vertical damping.
This will generally create a “lag” time effect to the camera as it aims at a target rather than leading the target as the Lookahead Time setting did.
By combining the Lookahead Time settings with the Damping settings, you can sort of dial-in a more “realistic feel” to the camera, as if a person were actually operating it.
Aim Composer (Screen X & Y)
“Horizontal screen position for the center of the dead zone. The camera rotates so that the target appears here.”
Or vertical screen position for the Y setting.
This will let you position the camera so that the target aimed at is consistently shown by the camera in an off-center manner.
I imagine these settings could be played with to add camera shake effects through code with Time.deltatime.
Aim Composer (Dead Zone Width & Height)
“The width of the screen region within which the camera ignores any movement of the target.
If the target is positioned anywhere within this region, the Virtual Camera does not update its rotation.
This is useful for ignoring minor target movement.”
Sometimes being too precise or exact during movement can give a Camera a very mechanical or non-human “feel” to our game or cutscene.
Also, if slight movements happen rapidly, it may drive the viewer nuts due to excessive jitter.
Dead Zones let us dial in on these issues.
Generally speaking we wouldn’t want to have dead zones that are a sizeable amount of the screen, or we can actually cause the non-human feel we are trying to avoid!
Instead of following too precisely, we would be following too sloppily.
Aim Composer (Soft Zone Width & Height)
“The width of the soft zone.
If the target appears in this region of the screen, the camera will rotate to push it back out to the dead zone, in the time specified by the Horizontal Damping setting.”
These are the red areas in the Game view.
Once the target game object exceeds the bounds and enters this red zone, the VCam will automatically adjust to keep the target “in frame”, or viewable.
Think of a spectator filming a car race.
As the car starts and moves towards the spectator, being far away, it is easy for the spectator to keep the car in frame.
As the car reaches and then passes the spectator, it is more difficult for the spectator to keep the race car in frame as it zooms right by them.
The spectator might incur whiplash trying to keep up!
With soft zones, the VCam will never let that target game object, say a race car, veer off screen.
No matter how fast the movement is across the Camera frame.
Note that our dead zones can never exceed our soft zones.
Aim Composer (Bias X & Y)
“Positions the soft zone horizontally, relative to the dead zone.”
The Bias X and Y settings will offset our soft zones accordingly.
Trying to drag a VCam around a scene with the gizmos can get your camera to the view you desire, but there is a much simpler and easier way!
In your scene view, navigate until you have the view setup that you wish the camera to “see”.
Click GameObject > Align With View and Voila!
The Transform on your selected camera will duplicate your current scene view.
As you can see, I’ve used this method to setup 4 additional VCams in a semi-circle pattern that will provide different angles of view for our scene when activated.
Note that if we disable an active VCam, the VCam with the next highest priority will automatically take over.
We’ll dive into switching between our VCams in code in the next article!