Search Unity

m_xAxis value 0 is not always behind target.

Discussion in 'Cinemachine' started by mrCharli3, Sep 2, 2019.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    405
    I use the following to reset the camera when the player dies, after the player respawns I call:

    Code (CSharp):
    1. public void ResetFreeLookCameraPos()
    2.     {
    3.         ActivePlayerCam.PreviousStateIsValid = false;
    4.         ActivePlayerCam.m_XAxis.Value = 0;
    5.         ActivePlayerCam.m_YAxis.Value = 0.5f;
    6.  
    7.         ActivePlayerCam.gameObject.SetActive(true);
    8.     }
    It does what it's supposed to, however, m_xAxis is not always behind target when the value is 0, sometimes value 0 is in front of the character, then I have to spin the camera 180 degrees to get it behind the target.

    What could be causing this? seems so random.

    I use Target forward, Lock to target on assign with Inherit position = false.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    Don't use LockToTargetOnAssign, use LockToTarget or LockToTargetWithWorldUp.
     
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    405
    Was afraid of that, Lock to target on assign is literally the only one that works for me. Maybe I can re-assign it somehow after the player spawns?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    Yes, you can try setting the target to null, then setting it back. That might force it to take a new snapshot
     
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    405
    Solved:

    Code (CSharp):
    1. public void ResetFreeLookCameraPos()
    2.     {
    3.         ActivePlayerCam.PreviousStateIsValid = false;
    4.         ActivePlayerCam.m_Follow = null;
    5.         ActivePlayerCam.m_LookAt = null;
    6.  
    7.         ActivePlayerCam.m_XAxis.Value = 0;
    8.         ActivePlayerCam.m_YAxis.Value = 0.5f;
    9.  
    10.         ActivePlayerCam.m_Follow = ActivePlayer.gameObject.transform;
    11.         ActivePlayerCam.m_LookAt = ActivePlayer.gameObject.transform;
    12.         ActivePlayerCam.gameObject.SetActive(true);
    13.     }
     
    Gregoryl likes this.