Intelligent Camera Switching Using Clearshot Cameras in Cinemachine
Objective: Learning how to use Clearshot Cameras in Cinemachine.
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
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.
I am simply going to move my capsule forward to the open space in the corner of the walls and see what happens:
Adding Children Virtual Cameras
Within the Inspector while we have the clearshot view game object highlighted, head down to the ‘Virtual Camera Children’ section and press the ‘+’ symbol so we now have 2 children virtual cameras.
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 ‘LookAt’ target. 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 ‘LookAt’ target.
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.
Success!
Useful Links
Cinemachine Clear Shot Camera