Intelligent Camera Switching Using Clearshot Cameras in Cinemachine

Chris Hilton
3 min readJan 26, 2022

--

Objective: Learning how to use Clearshot Cameras in Cinemachine.

Cinemachine Clearshot Camera

Compared to the state driven camera we just looked at, instead of a virtual cameras activation being dependant on the animation state of the ‘Animated Target’, the clearshot camera will intelligently look through its list of children virtual cameras and choose the best quality shot based on a clear view of the target, automatically switching to it. It is fast and easy to build a dynamic, smart and responsive camera system.

Note: An important note here is that if multiple children have the same quality shot, it will resort to look looking for the child virtual camera that has the highest priority.

How to Create a Clearshot Camera

Very simple! Make sure you have Cinemachine installed from Unity’s Package Manager and then along the top tabs press Cinemachine → Create Clearshot Camera. It will now be sitting in your Hierarchy as a game object.

Clearshot Camera Settings in Inspector

Clearshot Camera Settings

Similar to other cameras in Cinemachine, this has the Priority, Follow and LookAt features. But more importantly it has 2 features — ‘Default Blend’ and ‘Custom Blends’ which can help define the behaviour of the virtual cameras as they are blending between each other.

Let’s Build a Scene

For test purposes to see how this camera works, I have built a very basic scene with a capsule that simply moves forwards and backwards and 2 walls so that we can see what happens with the clear shot cameras when the capsule changes positions.

Scene with the 2 walls and a player capsule

I am simply going to move my capsule forward to the open space in the corner of the walls and see what happens:

Moving player capsule forward to the open space between the walls

Adding Children Virtual Cameras

Within the Inspector while we have the clearshot view game object highlighted, head down to the ‘Virtual Camera Childrensection and press the ‘+symbol so we now have 2 children virtual cameras.

Adding a new child virtual camera

Make Sure to Adjust in Scene

Now it is time to move the children virtual cameras in the scene so we can watch the camera switch take place. The first one I have put on one side of the wall and made the capsule the ‘LookAttarget. The second camera is on the other side of the wall and can’t see the capsule until it has moved into it’s view. This camera also has the capsule as the ‘LookAttarget.

The player capsule is in the view of virtual camera 1 and when it moves forward it won’t be, so it will automatically switch to virtual camera 2

Test Time!

Let’s move our capsule forwards and backwards and see if the virtual cameras will automatically switch based on the best quality/clear view of the target.

Clearshot cameras automatically switching between each other based on the best view

Success!

--

--

Chris Hilton
Chris Hilton

Written by Chris Hilton

Passionate Unity Game Developer

No responses yet