ClearShot with Orthographic cameras

Maybe I’m using this incorrectly, but even when the LookAt GO is not visible the ClearShot vcam is not picking a better shot.

I have 2 vcams tracking an object, each with its own offset, they have the confiner and collider extensions enabled. The tracked object has a box collider 2D and a rigid body and the “blocking” object also has a box collider 2D.

Here is a gif to show the issue: Screen capture - 2cb2003d408c522ace6d814147c7ea6c - Gyazo

CM vcam1 is always the one selected by ClearShot, even when it can’t see the target but CM vcam2 can.

Any ideas? I can upload a sample project if that helps.

A common thing that happens with ClearShot is that the LookAt GO itself becomes an obstruction, so ClearShot thinks the object is always obstructed and doesn’t bother to switch cameras. There are 3 ways around this:

  1. Set the Minimum Distance From Target field large enough to exclude the target GO. Obstacles within this radius will be ignored.

3474417--276107--upload_2018-4-25_16-2-7.png

or,

  1. Set the Ignore Tag field. All obstacles holding this tag will be ignored. Be sure to tag the ENTIRE player hierarchy - if it has children without this tag, they will not be ignored.

3474417--276108--upload_2018-4-25_16-2-58.png

or,

  1. Put the the LookAt targets and obstacles on separate layers, and set the collider’s layer filter

3474417--276109--upload_2018-4-25_16-4-42.png

Hello @Gregoryl , thanks for your answer. I’ve tried your recommendations but I still can’t get the ClearShot to recognize the obstruction.

Here is a sample project: https://github.com/urrutipi/2D-ClearShot

Just to be on the safe side, I’ve added the Player tag to the LookAt GO and moved the rest of the objects to the “Things” layer

Then on the vcams, I’ve set the Collide Against to “Things” and the Ignore Tag to “Player” but still no luck.

I had a look at it. It’s weird… why would you have 3D cameras with composers in a 2D world? Is is some special look you’re after? The composer makes the cameras pan and tilt, which feels wrong in a 2D game. Just my opinion.

If you remove the BoxCollider2D from the tree and put a BoxCollider instead, it works fine.

I’m not sure what you mean by 3D cameras, the vcams were created using the “2D Camera” menu of Cinemachine and have the orthographic size set to 3.

Yes, I’m trying to achieve some sort of “over the shoulder” shot. I have two 2D characters almost aligned on the X-axis, the one facing the camera has a small offset on the Z-axis. The required panning and tilting to find the best shot is minimal so the sprites are not deformed by the perspective (or lack of it).

When I manually control the vcams I get really close to what I need, but I was hoping the ClearShot vcam with Cinemachine Colliders would help me achieve the same or better results in a cleaner way.

I was able to make it work with 3D BoxColliders on the sample scene but that would mean ClearShot only works with 3D Physics. Do you know if there is any way to make it work with a BoxCollider2D or if that is planned?

Meanwhile, I’ll try to use 3D BoxColliders in my project.

Thank you!

ClearShot tests for obstacles (i.e. colliders) that come between the camera and the target. It does this by doing a physics raycast. The thing about 2D colliders is that they have infinite Z depth, so one cannot be “behind” another along that axis. Since in a 2D game the camera is raycasting along Z, that feature can’t work unless you have 3D colliders, which have a finite Z depth, and so can be behind each other.

Crystal clear! Thanks again for your support!