Search Unity

Question Cinemachine collider doesn't work like typical third-person game cameras

Discussion in 'Cinemachine' started by wilgieseler, Jul 12, 2022.

  1. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Unless I'm missing something, it seems like it's not possible to use Cinemachine Collider to implement a standard third-person game camera. This is a bit difficult to describe and perhaps a little subtle, so hopefully this explanation makes sense.

    Typically, a third-person game camera will prevent the camera from clipping into objects by moving itself forward – which is possible with Cinemachine Collider. However, most third-person games do this while still allowing you to place an object in between the character and the camera.

    For example, imagine a character standing near a tree. In games like Zelda: Breath of the Wild, orbiting the camera around will allow the tree to pass between the camera and the player without the camera zooming in. However, if you back the camera into the tree, the camera will get closer to the player, still preventing clipping.

    Playing with Cinemachine Collider I can't get anything that feels even close to right, because anything blocking the raycast to the player causes an awkward zoom in.

    Perhaps there's a way to accomplish this out of the box – I'm not sure what to call it so searching hasn't been fruitful. Does anyone know if that's possible, or if there are any resources that describe an optimal third-person camera setup in more detail?
     
  2. Auticus

    Auticus

    Joined:
    Jul 18, 2013
    Posts:
    99
    A painful alternative hack may be to disable colliders of terrain around you so the camera can move through it as the player gets close to it. Or even implement a raycast from the player in the direction of your camera and items it finds that are terrain it disables the collider for and then when you move out of the area, it enables them again.
     
  3. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    This is not really achievable out of the box. You could achieve something like this with setting Minimum Occlusion time, however it is not the same.

    I think it could be implemented as an extension to the current collider.
    Could you provide a detailed description of the use case? What is the exact behaviour you are looking for? Some examples (drawings, video recordings) could help illustrate the problem. Would you like to have specific objects that exhibit this behaviour (layer x), while others are not (layer y)?
     
    Last edited: Jul 14, 2022
  4. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Thanks for responding!

    I'm pretty sure that this behavior is very similar in every third-person game I can think of (Hitman, Uncharted, Assassin's Creed, etc.), I can try to gather more examples. My goal is simply to have a well-behaved camera like those games, I'm not 100% sure of the implementation specifics. Because it's so common I think it would be awesome if it was built-in to Cinemachine, but I'm happy to hack something together.

    I believe that this behavior applies to all objects in the game, based on some testing.

    Here's a recording of the camera in Zelda

    Here's my third-person camera WITHOUT cinemachine collider

    Here's my the camera WITH cinemachine collider

    You can see that without the collider, obviously the camera will happily clip into whatever, as expected.

    However, with the collider, getting an object between you and the camera results in unexpected, jarring, and ugly behavior when line-of-sight is broken because it zooms in way too close. I can't think of any games with this style of third-person control that do that, so it seems like the current collider implementation is optimized more for cinematics or other control schemes.
     
    gaborkb likes this.
  5. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    My guess at the implementation is that the camera has a collider on it but NOT a raycast, and if the camera bonks into something it will get closer to the player. If there is an object between the player and the camera you can move away from the camera and "pull" the camera through the object, but if you back up the camera will hit the object and cannot be "pushed" back through it. (This is specifically demonstrated in the Zelda example video.)
     
    gaborkb likes this.
  6. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Thanks for the detailed description.

    I think what you describe is actually achievable using the Transparent Layer. Set the tree's layer to Transparent Layer on CinemachineCollider. In this case, if the "tree" is placed in front of the camera, the collider won't react. However, if you back into the "tree" it will push the camera forward.
     
    Gregoryl and wilgieseler like this.
  7. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Oooooo good call! I've set my "Transparent Layer" to "Everything" and it seems to mostly work like this! I am still seeing some occasional clipping but maybe some of the other settings need to be tuned.
     
  8. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Setting it up with everything on the Transparent layer definitely works better than before, but there's still some definite weirdness. In particular, there are lots of discontinuities when orbiting, but I'm not sure what's causing the camera to move like this. Here's a video showing the discontinuities (I'm playing with a controller and orbiting smoothly in this clip.)
     
  9. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Here are the collider settings I'm using:

    Screen Shot 2022-07-14 at 12.43.41 PM.png
     
  10. TipsonXO

    TipsonXO

    Joined:
    May 8, 2017
    Posts:
    1
    Hi wilgieseler,

    What is your basic camera setup? Can you post a screenshot of that?

    Cheers!
     
  11. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Trying now to just exclude smaller objects via layers/tags, but still can't figure out why the camera is translating weirdly when occluded instead of pulling forward. Here's a screenshot of most of the camera settings.
     

    Attached Files:

  12. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Been playing around improving the settings and I think "Camera radius" is what causes the discontinuities.
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    It may be the case that you have some invisible orphan collider in the scene that the camera is picking up and colliding with. It would help if you could show the scene view, with the vcam in question selected so that the yellow collision resolution debug lines are visible. That would help figure out what exactly is getting collided with.
     
  14. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    84
    Oh those collision debug lines are very helpful! Still tweaking things, trying to reformulate my question since I'm trying the recommended approach of simply manually specifying which items the camera can collide with. Not how Zelda works, but seems that Hitman works similarly to that with pretty good results.