Search Unity

Camera Collision without Occlusion

Discussion in 'Cinemachine' started by BorisTI, Jun 1, 2019.

  1. BorisTI

    BorisTI

    Joined:
    Apr 21, 2012
    Posts:
    19
    Hello,

    These tools are great! Thank you for providing this.

    I'm trying to setup a camera that has collision, but doesn't pull forward on occlusion. Effectively, I want the camera to pull forward when it hits the wall, but not when the character passes in front of one.

    I have a workaround of making the Minimum Occlusion Time really high, but it doesn't solve all the problems.

    Current issue with workaround: If the user backs up into a wall with a "Freelook" camera, the camera starts to pull forward until the active point in the spline pushes out the back side of the wall. The camera then pulls back to its active position on the spline.

    Is there a solution I'm missing that's already provided?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,721
    The collider will not pull the camera in front of any obstacles on layers that you specify in the "Transparent Layers" dropdown. So you can try something like this:

    upload_2019-6-4_11-10-20.png
     
  3. BorisTI

    BorisTI

    Joined:
    Apr 21, 2012
    Posts:
    19
    That fixes needed the workaround, thank you. The problem is that the camera pushes through the backside of the collision when the orbit position has moved beyond the collision.

    20190605133504_Trim.gif

    What I'm looking for is having the camera only pull back when there is clear space behind it, and pull forward when it hits collision at any point / face.

    Thank you for the help.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,721
    Looks like you'll have to make a custom version of the collider extension. Copy CinemachineCollider.cs into your assets, rename it (and the class), and modify as needed.

    As far as I can tell, the algorithm you're asking for is:

    Code (CSharp):
    1. if (camera radius intersects an obstacle at the desired camera position)
    2. {
    3.     pull the camera out of the obstacle, in the direction towards the target
    4. }
    Does that sound right?
     
    Last edited: Jun 5, 2019
  5. BorisTI

    BorisTI

    Joined:
    Apr 21, 2012
    Posts:
    19
    That sounds exactly right. Trying to figure out how to do that.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,721
    Thinking about it some more... actually it's a little tricky. As the FreeLook approaches the wall, if you implement it naively as described, at one point the vcam will pop out behind the wall, because the orbit radius is large enough that the vcam will want to go there. The custom collider will conclude that there is no obstruction :(
     
    Last edited: Jun 6, 2019
    BorisTI likes this.