The Power of Virtual Cameras
Using Cinemachine with Virtual Cameras puts a virtual crew of camera riggers, light holders, directors, actors and editors at your fingertips to achieve your cinematic artistic vision.
Create a Virtual Camera
While cinemachine offers a wide variety of specialized camera features, I will get going here with the basic Create Virtual Camera option.
A new CM vcam1 (CineMachine Virtual Camera 1) appears in the hierarchy.
Each virtual camera you create has a plethora of options available. Let’s go through a few of them one at a time. The main Transform component controls the Position and Rotation of the camera. Typically, these are the options that would be meticulously controlled via code, before awesome tools like cinemachine to do the work for you.
As a shortcut for garnering a camera view, use the scene view to get the image that you want your camera to capture, select the camera you want to use in the hierarchy, and then press Shift + ctrl + F, to align the scene view coordinates to the selected camera.
I add a second virtual camera into the scene to showcase some more cinemachine options.
The Solo button can be used to force the game view to show that particular virtual camera. If you have a lot of cameras in your scene, the solo button can be your friend to quickly make sure you are seeing the camera view you want.
I offset the two cameras in my scene to show the solo button in action. This is solo camera 1.
This is solo camera 2.
The Look At function is a huge time saver. The Unity documentation provides a perfect reference for transform.LookAt(target). Assigning an object to the LookAt on the camera is akin to making a script on the camera that finds a target, and then rotates towards it every frame update. This function will use the rotation of the camera to lock the camera on to the assigned targets position.
Simply drag the object that you want the camera to rotate towards, into the Look At assignment box from the hierarchy. After dropping the Player Capsule into the Look At assignment, you can see the X and Y rotation values change as the camera turns towards the player.
The Game Window Guide checkbox is only available when you have an object assigned to the Look At.
The blue box below can be seen in the virtual camera screen with a Look At assignment.
Enable or disable the blue box with the Game Window Guide toggle option.
Under most circumstances, Unity will not save changes made in the inspector while the game is running. Enable the Save During Play option to turn on that feature.
The Priority number is how to control which virtual camera is showing through the game view. The camera with the highest priority value will be the active one showing, so adjusting this value is an easy way to switch between cameras.
If the virtual cameras all have the same Priority value, a random one will be selected to be in control. Let’s change the Priority of the second camera to be 11, which will make it show over the first camera with a priority of 10.
Camera two rotates to follow the player around the game scene, while staying still regarding camera position.
I drag the player capsule into the Follow assignment box. Similarly to how Look At uses the cameras rotation to track a target, the Follow function will change the position of the cameras transform to move with the assigned target.
Now the camera follows the players as it moves, rather than just rotating towards it from a stationary position.
The Field of View changes the how wide or narrow the lens on the camera is. Turning this value way up gives more of a long distance 250mm lens effect with a low depth of field. Lowering this value creates a wider shot with a greater overall depth of field.
The Near Clip Plane dictates how close an object can get to the camera before it gets removed from the scene. Sometimes you can see that if an object is too close, part of it will get visibly cut off. The Far Clip Plane is similar, only working with how far away an object can get from the camera before it disappears.
The Dutch function will tilt the camera left and right on the Z axis, rather than doing it the old fashioned way through code work!
Here is a Gif of me adjusting the Field of View value. You can see the Field of View changing in the scene view, and see the camera adjusting in the game view.
Here the value of the Dutch function is adjusted.
Here is the tilted camera result.
These occur when one virtual camera switches to another. There are some preset options that can be selected depending on what kind of camera transition you want.
I will get more into this in my next article, but the Tracked Object Offset values are perfect for having the camera not perfectly center the target that it’s following.
There are a lot of aiming options as well as Extension Addons that we can tackle next in a more detailed article about the Aiming features in cinemachine. Thanks for reading and I hope to see you next time!