Day 99: Intelligent Camera Switching Using Clearshot Cameras

Simon Pham
2 min readOct 6, 2023

--

In this article, I’ll guide you through the process of switching between cameras based on the visibility of your target object using Clearshot Cameras.

Scene Setup

For this demonstration, I’m going to create a simple scene with two walls and a capsule character.

Clearshot Camera Setup

Next, we’ll set up two virtual cameras at different angles as shown below:

Camera 1
Camera 2

Now, navigate to GameObject > Cinemachine > ClearShot Camera. You’ll notice that a ClearShot Camera GameObject has been added to the Hierarchy, containing a child Virtual Camera. We can delete this camera and drag the two cameras we set up earlier into this GameObject.

You might have noticed the warning from Unity regarding the need for a Collider extension for the child cameras.

To fix this,select both child cameras, navigate to the Extensions property, and choose the CinemachineCollider extension from the Add Extension dropdown list. Once you’ve done that, the warning should disappear.

Let’s also set the Body property to “Do Nothing” and ensure that the “Avoid Obstacles” option is checked for both cameras.

Now, let’s hit “Play” and see the result:

You can see that as soon as our vision is obstructed by a wall, it switches from camera 1 to camera 2, and vice versa.

--

--

No responses yet