Search Unity

Cinemachine Collider's "Pull Camera Forward" not damping the way I wanted

Discussion in 'Cinemachine' started by EMdevv, May 21, 2020.

  1. EMdevv

    EMdevv

    Joined:
    Mar 11, 2020
    Posts:
    6
    I have a weird specific issue that I don't know how to solve.

    I'm using a free-look camera with mouse controls. I put on a collider with the "Pull Camera Forward" setting on. But when I apply damping to the collider through the provided damping slider, it tries to damp the entire camera movement instead of just the "pulling back" of the camera.

    This creates some pretty annoying controls where you try to move the camera and the damping fights back.
    I just want the camera to pull back smoothly without it affecting the axis values, how do I achieve this?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The Collider attempts to preserve the screen position of the LookAt target when it displaces the camera. That implies that sometimes the camera might rotate. It's possible to have a version of the collider that doesn't do that. If you want to try it, let me know.

    However, without knowing more about your usecase, I'm wondering whether you have the right camera setup for the job. A FreeLook is designed for following and looking at a player. If in fact you're really looking at something else while following the player, maybe a different camera rig would be better. The LookAt target is an important hint for Cinemachine, and if it's set inaccurately (i.e. if you're really interested in looking at something else) then you will be fighting with the system.

    Can you describe your usecase a little?
     
    Last edited: May 21, 2020
  3. EMdevv

    EMdevv

    Joined:
    Mar 11, 2020
    Posts:
    6
    I'm trying to create a mouse and keyboard third person game. As of now I have a FreeLook camera following and looking directly at the player as you described. I wanted the Pull Camera Forward damping to smoothly pull back the camera after a collision has happened, but it also affects my orbital rotation of the camera which I don't want.

    Since this is a mouse and keyboard game, I don't really want any external forces fighting the player's mouse movements. Here's a short video I recorded showing the unintended behavior:
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The collider is preserving the screen position of your LookAt target. It's the lesser of the evils, because if it didn't do that and instead preserved the camera rotation when displacing the camera, then your LookAt target would move around on the screen.

    It's not clear to me what you would like the camera to do in this situation.
     
  5. EMdevv

    EMdevv

    Joined:
    Mar 11, 2020
    Posts:
    6
    I apologize, I'm having a hard time explaining what I'm referring to because I don't know all the correct terminology.

    I want the camera to preserve the screen position of my LookAt target, that's not the issue.
    It's when the camera pulls BACK to the original distance to the player, that it does a weird orbital damping.

    As seen in the video, even though I stopped moving my mouse, the camera orbits slowly to the opposite side of my mouse movement for a little while.

    All I want the camera to do is smoothly pull back the camera to the original camera distance WITHOUT it affecting the orbital rotation of the camera.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    It's not actually changing the orbit of the FreeLook. When the camera is next to the wall, the collider applies an offset to take it out of the wall - pushing the camera towards the player. Then you move the mouse, orbiting to remove the obstacle. Now, the camera is free to return to the desired position, so it does that. But, because you have nonzero damping (let's say it's set to 2), then it takes 2 seconds to gradually remove that offset. That's the slow lerp you're seeing.

    Just thinking aloud here: the offset is in worldspace. Would it make sense perhaps to rotate the offset along with the camera when the axis changes? Do you think that might address the issue you're raising?
     
    Last edited: May 28, 2020
    mahnoorcodes likes this.