Search Unity

Kind of dissapointed by Cinemachine's obstacle avoidance. Am I missing something?

Discussion in 'Cinemachine' started by jwvanderbeck, Feb 26, 2019.

  1. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Overall I find Cinemachine to be a damned impressive piece of kit, and it does some amazing things. However this weekend I was trying to work with some stuff and was really let down by the limited feature set it appears to have for obstacle avoidance and I am wondering if I am just missing something.

    One of the driving features behind Cinemachine was, to my understanding, solving the more challenging engineering issues that many different games have to re-implement on their own, and obstacle avoidance is definitely one of those things. It is hard to get right and takes a good lot of work.

    But all I can seem to find for doing this with Cinemachine is the Collider behaviour which does nothing more than pull the camera forward of any collider it hits. It doesn't check to maintain line of sight, and it doesn't make any attempt to smoothly nudging the camera in a way to keep the player's comfort level up. It just teleports the camera to the other side of a collider it hits.

    Is there something else in this package that I am missing?

    Amazingly good talk about the subject by the way:
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Indeed it sounds like you are only scratching the surface of what the CinemachineCollider can do. Change the Strategy to something other than PullCameraForward to expose the other features.

    upload_2019-2-26_10-54-12.png

    The smoothing and damping controls are quite powerful, as is the filter system for choosing collidable and transparent layers. It does take some tinkering to get it just right, and the precise values you choose will depend on your game.

    Are you by any chance using an old version of Cinemachine? Maybe that's why you didn't see this stuff. The latest version is 2.2.8, available via the package manager (not the asset store).
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    How close to walls can the camera collision get? in my code, I project the frustum of the camera so it can get to basically, ground zero without clipping problems. If Cinemachine can reach that far I could consider using it instead of custom...
     
  4. JohnVandebeck_MPCFilm

    JohnVandebeck_MPCFilm

    Joined:
    Jan 28, 2019
    Posts:
    2
    I have tried all of those settings, though blindly as I don't know what they are supposed to do :) But no matter what I do I still get camera "teleporting" which is very confusing to the player. I don't ever want the camera to jump from one spot to another. It should always MOVE smoothly from one spot to another.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Then you need to be setting the damping values. Maybe you can post an image of the inspector showing the settings you're trying?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    That's controlled by the Camera Radius value. It defines how close the camera can get to the obstacles.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Oh nice! thank you.
     
  8. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Ok I've started getting some of the behaviour I Wanted thanks. I was increasing the damping but I needed to be increasing the Damping When Occluded. Somehow I totally missed that second setting first time around.
     
    Gregoryl likes this.
  9. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    So after playing with this and getting a feel for it, it is better than I originally thought, though not really advanced enough I think for most games that really was nice polish on their game cameras.

    This well help you keep your camera from losing line of sight, and keep it from "sitting" inside the world geometry, but it seems at best all it will do is pull the camera forward to clear obstructions. It still allows the camera to go through geometry, just in a more controlled manner. This is fine for many games, but if you are looking for a more polished system that actively pushes the camera AROUND obstacles then this just doesn't seem up to the job.

    That said, this is adequate for many games, but I'd like to suggest a few more options for control here.

    I feel like you need individual control over two similar but separate conditions.
    1) When the cameras path pushes it into an obstacle and the camera just needs to not penetrate the obstacle.
    2) When an obstacle comes between the camera and the target

    In case 2, you probably want a bit of damping so that the "pull forward" isn't disorientating to the player, but in case 1 you want no damping because you just want to the camera to stop when it hits the obstacle. If you have any dampening in case 1 then the camera will temporarily get pushed through the obstacle and then pull itself back out which looks bad. So you really need two different damping controls here.

    On the surface that should be what "Damping" and "Damping when Occluded" would be, with the first covering case 1 and the second covering case 2, but this doesn't seem to hold true. In fact I seem unable to find a scenario where the plain "Damping" is used.

    Complicating case 1 even farther, is there really are two values needed here. Essentially the "pull forward" and "push back" need to be tweakable separately. In this case you generally want damping at 0 to prevent the camera from moving into the obstacle temporarily, but if you have it at 0, then when the camera is clear to "push back" to its normal distance it does so instantly which can be disorientating at worst, and ugly at best.

    Lastly there is some odd behaviour that I don't even know how to explain, such as this here. What is going on here?

    https://i.gyazo.com/10394b3845be067cdeede9ef5d872f58.gif
     
    Last edited: Mar 4, 2019
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Interesting. Can you post a little more info on that case?
    It would be good to see the scene view from above, showing the camera and the colliders clearly.
    Also it would be very helpful to see the CinemachineCollider inspector.
    And to have an understanding of the layers involved.
     
  11. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Is this what you want? Anything else?







    As far as layers go, there are really only two layers involved in this test. Default and "Puck". Puck is the short cylinder inside the character and is part of the movement system. It is only being shown as debug and is ignored from any collisions, and the camera collider is set to ignore it as well.
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    What I was hoping for was a moving image of the scene view from above, so I could understand the geometry a little better and get a handle on what colliders are involved in the weird motion. As it is, it's a little hard to tell.

    It almost looks as though there's an invisible collider blocking the doorway, and that the camera is being pulled in front of it, and then pushed up in an attempt to preserve the height. It seems that the character is standing just inside the door, so there's nowhere for the camera to go, that's why it's up so tight against the character. At least that's what it looks like. Hard to tell from here.
     
  13. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
  14. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    There is no collider in the doorway itself as if there was the player wouldn't be able to move through.
     
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Can you try disabling the collider on the house? Clearly the vcam is bumping into something.