Search Unity

Question Cinemachine Collider - how to damp only the distance?

Discussion in 'Cinemachine' started by Awarisu, May 11, 2020.

  1. Awarisu

    Awarisu

    Joined:
    May 6, 2019
    Posts:
    215
    I have a relatively simple setup with a FreeLook camera with a collider script on it, with the Pull Camera Forward strategy. It *almost* does what I'd like, the problem I'm having is that whenever the damping kicks in due to a collision it damps both the camera's distance from its target as well as its angle, giving it a temporary springy or "late" feel when controlled via, e.g., mouse look. Is there a way to only dampen the distance between the camera and its target and not the angle it's viewing it from without hacking the source code?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The CM collider tries to maintain the screen position of the LookAt target - not the camera forward. In the case of the FreeLook, the LookAt target is the player, usually. Are you in fact wanting to maintain the camera forward?

    If this is a 3rd-person situation, consider upgrading CM to the latest 2.6. preview. There are new CM components designed specifically for 3rd person where maintaining aim is primordial. Have a look at the new example scenes AimingRig and 3rdPersonWithAimMode.

    Finally, to answer your actual question, the way to do it would be to write your own customized version of a collider extension that simply pulls the camera forward without changing its angle. Quite simple and easy to do. You can start by copying the CM collider, then delete most of the code and keep only the PullForward part.
     
    Last edited: May 11, 2020
    Awarisu and gaborkb like this.
  3. Awarisu

    Awarisu

    Joined:
    May 6, 2019
    Posts:
    215
    Thank you!