Search Unity

Question Cinemachine Camera Follow goes off target when Player Falling

Discussion in 'Cinemachine' started by punkrooks, Sep 22, 2021.

  1. punkrooks

    punkrooks

    Joined:
    Apr 15, 2016
    Posts:
    35
    Currently I was trying to achieve a smooth transition and camera follow when the player was falling.
    But, When player falls it either goes :

    1. On Increased Y Damping -> Follow is Smooth, but player is off camera when falling
    2. On Increased Y Damping and also Increasing Y Soft zone Height -> same as the first one
    3. On Decreased Y Damping -> Follow is Harsh, but Player is in camera
    4. On Increased Y Damping and decreasing Y Soft zone Height -> same as 3.

    Q: How can we have both smooth transition as well as not loose track of the player when falling ?
    I was thinking if we can also enable lookahead for Y when falling, currently it is enabled but lookahead doesnt seems to work on falling.


    I have explained the scenario in more details here as well:
    https://stackoverflow.com/questions/69279505/unity2d-player-off-camera-on-falling-with-cinemachine
     
    Last edited: Sep 22, 2021
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    It sounds like you're looking for 2 different camera behaviours, depending on whether or not the player is falling. You can set this up with 2 vcams A and B, identical except for a difference in the damping setting. When the player is not falling, enable vcam A, when it it falling, enable vcam B.

    Alternatively, you can try to do it with a single vcam with a custom script that modifies the vcam damping setting. When the player begins to fall, decrease the damping. When the player is not falling, bring the damping back to normal.
     
    punkrooks likes this.
  3. Piotrone

    Piotrone

    Joined:
    Mar 6, 2015
    Posts:
    36
    I have the same problem. I'm trying to change the YDamping as suggested by @Gregoryl but it's not working.
    Here's what is happening:


    I've attached a pic with my Framing Transposer settings. I want the player to not be centred on the Y so I changed the "Tracked Object Offset"

    Here's the code (I've verified and _playerMovement is returning the correct values)

    Code (CSharp):
    1. public class VirtualCamera : MonoBehaviour
    2. {
    3.     private CinemachineVirtualCamera _camera;
    4.     private PlayerMovement _playerMovement;
    5.     private CinemachineFramingTransposer _transposer;
    6.  
    7.     private void Awake()
    8.     {
    9.         _camera = GetComponent<CinemachineVirtualCamera>();
    10.         _transposer = _camera.GetCinemachineComponent<CinemachineFramingTransposer>();
    11.         _playerMovement = FindObjectOfType<PlayerMovement>();
    12.     }
    13.  
    14.     public void Update()
    15.     {
    16.         if (_playerMovement.isGoingDown)
    17.         {
    18.             _transposer.m_YDamping = 1;
    19.         }
    20.         else if (_playerMovement.isGoingUp)
    21.         {
    22.             _transposer.m_YDamping = 10;
    23.         }
    24.     }
    25. }
    26.  
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
  5. Piotrone

    Piotrone

    Joined:
    Mar 6, 2015
    Posts:
    36
    Thank you, that solved the problem and that thread looks promising, I'll try it out!