Search Unity

Bug Cinemachine does not respect collider extension when combined with freelook

Discussion in 'Cinemachine' started by awiebe, Apr 19, 2021.

  1. awiebe

    awiebe

    Joined:
    Oct 16, 2018
    Posts:
    14
    I've been trying to combine the CinemachineFreeLook VirtualCamera with the Cinemachine collider extension to enhance the rig that came with the 3D game kit. It does not behave as expected as it passes through walls and is also quite erratic in tight spaces.

    What I Want
    If I am using a freelook camera and the result of my input would be pushing the camera through a wall, then Cinemachine should prioritize collision avoidance and ignore my camera input on the offending axis for that frame. At a minimum the cinemachine collider should be doing this, right now it will push through the wall. What follows is other things that are needed by the cinemachine collider to make sense in freelook.

    Additionally right now a camera can only preserve height or distance, a behavior which is disorienting when using freelook. A third mode is needed that tries to preserve distance and then height by pivoting instead of zooming. Ideally the Camera should be repelled by the wall to maintain distance and when possible height, as though on a rigid boom at a fixed pivot distance from the follow target. If the camera radius is being pressed against a surface while being dragged by the follow distance, it should attempt to pivot around follow target to avoid the obstruction, this can take on two behaviors.

    If pivoting around lookAtHeading.up, both height and distance can often be preserved, because the obstruction has flanked the camera from left or right but there is not a ceiling in the way.

    If a ceiling creates the obstruction then the camera needs to be pivoted around lookAtHeading.right, this preserves distance by sacrificing height.

    By analogy imagine you stuck the camera on a very long selfie stick and had to maneuver it through a corridor.


    Right now if the lookat gets into a tight spot the camera avoidance can be quite sporadic, because it does not attempt to maintain composer orbits in the same manner as the player inputs.

    Looking at the code it looks like it tries to do a form of recursive ray bounce based repositions that obey distance(by calling the zoom strategy). Basically this adds one more step before that where you see if you can pivot horizontally(since you want to preseve height) and then vertically if still needed(to preserve distance), and then you can fall back to the other strategies.

    What Happens
    Pushing the Cinemachine CameraX causes the Cinemachine camera to penetrate the wall and then try to de-penetrate it, rather than smoothly sliding along it. Setting the damping too low causes it to jump erratically, setting the damping up causes it to slide through the wall and render, then gradually slide back to a reasonable position, but it rendered behind the wall which defeats the purpose.

    Reproducing the issue
    1. Load the 3d game kit
    2. Place a vertical plane in the scene and set it to a layer the CinemachineCollider will collide with.
    3. Walk the player next to the wall and shift the mouse causing the camera to jump.
    4. Set the damping and damping while occluded to 2, repeat step 3.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Have you tried replacing the FreeLook camera with a 3rdPersonFollow rig? See the AimingRig sample scene for an example of this. We think it's much better suited than FreeLook for this kind of camera. It has built-in collision resolution, so you don't need to use the CinemachineCollider.
     
  3. VResearch

    VResearch

    Joined:
    Jan 6, 2021
    Posts:
    21
    So right now there's still no way to make free look cam work with colliders? Feels like an oversight... What if we want orbit camera which does not penetrate solid objects?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    FreeLook works with CinemachineCollider. However, if you add CinemachineCameraOffset to it then it will not play nicely with CinemachineCollider. For that kind of over-the-shoulder camera, we recommend 3rdPersonFollow.
     
  5. VResearch

    VResearch

    Joined:
    Jan 6, 2021
    Posts:
    21
    This is not consistent with my current experience. I have a CinemachineFreeLook set up. I do not use Cinemachine CameraOffset. I do use Cinemachine collider. The result is that camera does not go through colliders that are horizontal but happily penetrates anything vertical. I've tried different Strategies and playing around with the settings but nothing works so far...
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    If you would like to send me a simple test scene that shows this problem, I can take a look at it. For me the collider works on both horizontal and vertical surfaces.