Search Unity

Why does YAW cause Roll as well?

Discussion in 'Physics' started by sietse85, May 5, 2019.

  1. sietse85

    sietse85

    Joined:
    Feb 22, 2019
    Posts:
    99
    Hi People,

    I am trying to yaw a ship without rolling.

    Code (CSharp):
    1.  
    2. private void GetMouseInput () {
    3.         lockZ = true;
    4.             // roll = Input.GetAxis ("Roll") * a.speedRoll * Time.deltaTime;
    5.         pitch = Input.GetAxis ("Vertical") * a.speedYaw * Time.deltaTime;
    6.         yaw = Input.GetAxis ("Horizontal") * a.speedPitch * Time.deltaTime;
    7.     }
    8.  
    9. private void UpdateRotation () {
    10.         yaw = Mathf.Clamp (yaw, -0.5f, 0.5f);
    11.         pitch = Mathf.Clamp (pitch, -0.5f, 0.5f);
    12.         roll = Mathf.Clamp (roll, -0.5f, 0.5f);
    13.         t.Rotate(pitch, yaw, roll);
    14. }
    When pitching all is fine, the roll is untouched. But as soon as i YAW (eg move left or right) the Z-rotation (roll) gets adjusted as well. I have no idea why this is and it's driving me slightly nuts at this point. Any help is very welcome.