Virtual Cameras w/ Cinemachine in Unity 2020 — Part 1

Credit: https://www.youtube.com/watch?v=Gx9gZ9cfrys Brackeys

Virtual Cameras

“The Cinemacine Virtual Camera is a component that you add to an empty GameObject.

It represents a Virtual Camera in the Unity Scene.

Use the Aim, Body, and Noise properties to specify how the Virtual Camera animates position, rotation, and other properties.

The Virtual Camera applies these settings to the Unity Camera when Cinemachine Brain or Timeline transfers control of the Unity camera to the Virtual Camera.”

Cinemachine will essentially take you one “actual” camera in the scene and toss around it’s use to multiple “Virtual” cameras.

So, one virtual camera may be your player view, another may be for a cinematic cut scene triggered when the player reaches a certain point in a level, and a 3rd could be a alternate view, such as 1st person to 3rd person viewpoints.

All of these virtual cameras will make use of your Main Camera when appropriate.

“Cinemachine does not create new cameras. Instead, it directs a single Unity camera for multiple shots.

You compose these shots with Virtual Cameras.

Virtual Cameras move and rotate the Unity camera and control its settings.

The Virtual Cameras are separate GameObjects from the Unity Camera, and behave independently.

They are not nested within each other.

Cinemachine encourages you to create many Virtual Cameras.

The Virtual Camera is designed to consume little processing power.

If your Scene is performance-sensitive, deactivate all but the essential Virtual Cameras at any given moment for best performance.

It is recommended that you use a single Virtual Camera for a single shot. Take advantage of this to create dramatic or subtle cuts or blends.

One Virtual Camera has control of the Unity camera at any point in time.

This is the live Virtual Camera.

The exception to this rule is when a blend occurs from one Virtual Camera to the next.

During the blend, both Virtual Cameras are live.”

Cinemachine Brain

“The Cinemachine Brain is a component in the Unity Camera itself.

The Cinemachine Brain monitors all active Virtual Cameras in the Scene.

To specify the next live Virtual Camera, you activate or deactivate the desired Virtual Camera’s game object.

Cinemachine Brain then chooses the most recently activated Virtual Camera with the same or higher priority as the live Virtual Camera.

It performs a cut or blend between the previous and new Virtual Cameras.”

With Cinemachine, you can already start to imagine all of the legwork in coding that is being eliminated.

Transitioning between cameras, moving cameras and timing them to game events, properly generating the view based on look-at code, and camera effects such as shake are all much simpler and easier to implement with Cinemachine at your fingertips.

Not to mention all of the debugging all of this would entail!

Adding Virtual Cameras to Your Scene

Right clicking in our hierarchy and attempting to create virtual cameras from the dropdowns as we would lights, game objects, etc won’t work.

We need to click on Cinemachine at the top of our screen and create them from there.

The beauty of virtual cameras is in having multiple cameras, so I’ve created two for starters.

What is the Solo button?

VCams have a “Priority” value that determines which camera is “Live”.
The highest priority value VCam will be Live.

To make VCams easier to work with, Unity gives us a “Solo” button.

Instead of constantly changing the priority value just so that you can work with the VCam you need to at the moment, you can simply click the Solo button and that VCam will go Live regardless of its priority.

As you can see above, when we click the Solo button an inactive VCam goes live and the game / scene views both switch to that camera.

Let’s take a look at the settings of the CinemachineVirtualCamera component as described by Unity.

Game Window Guides

As you can see above, even though Game Window Guides is enabled, our game view does not show them.

They will only appear when we set a Follow or Look At game object.

Save During Play

“Check to apply the changes while in Play mode.

Use this feature to fine-tune a Virtual Camera without having to remember which properties to copy and paste.

This property applies to all Virtual Cameras.”

I can’t be the only one that has made changes in Play mode only to regret ending Play mode before I copied a component…

We’ve already covered Priority, let’s look at Follow and Look At.

Follow

This is going to be your player camera.

(Yes, it should be you’re, but why don’t you try finding a meme for everything you write)

Look At

Can you say cutscenes?

Player opened a chest and you want to force them to watch that painstaking animation of yours?

Player walked into the wrong neighborhood and you want to highlight the big bad boss that is going to make him rage quit?

This is the setting you’re looking for.

“The target GameObject to aim the Unity camera at. The Aim properties use this target to update the rotation of the Unity camera.”

Lens

The lens is our digital version of a camera’s lens.

Field of View

The FoV setting allows to widen or narrow the camera’s view of the scene.

This is often a player settings option as it determines how much of the game world the player can see on their screen.

A player with a higher FoV standing in the same position and orientation as another player, will have more peripheral vision of the game world.

Near Clip Plane

“The closest point relative to the camera where drawing occurs.”

Far Clip Plane

“The furthest point relative to the camera where drawing occurs.”

Dutch

“Dutch angle. Tilts the Unity camera on the z-axis, in degrees.”

You know in old TV shows and movies how they would make a completely stationary stage, such as a spaceship bridge on Star Trek, look like it was moving around?

You don’t?!

I can fix that:

If you can’t build your stage on a ton of hydraulics with electronic controls, why not just move the camera and make it seem like everything else is moving?

Add a bit of shaking and it looks like a rough ride!

Yes, the actors play it up too.
But what does it look like without the camera shakes and twists?

I’m glad you asked!

Lame, right?

Mode Override

“Allows you to select a different camera mode to apply to the Unity camera component when Cinemachine activates this Virtual Camera.

Important: All the changes applied to the Camera component through this setting will remain after the Virtual Camera deactivation.

If you set a mode override in any Virtual Camera, you should set one in all Virtual Cameras.”

Mode override choices include, None, Orthographic, Perspective, and Physical (whatever settings are on the Main Camera basically).

Blend Hint

“Provides hints for blending positions to and from the virtual camera.”

Inherit Position

“When enabled, whenever this virtual camera goes live, forces the initial position to be the same as the current position of the Unity Camera, if possible.”

In certain use-cases, you’ll want the virtual camera to inherit its position from the previous camera.

Add Extension

Extensions add new camera behavior to our VCams.

For instance, the CinemachineCollider and CinemachineConfiner are useful to avoid the camera “running into” game objects or if you want the VCam to be limited to a certain volume or area.

I think that’s enough for this article, we’ll do a Part 2 in our next article on Virtual Cameras.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store