Search Unity

Question Players Rotation keeps snapping back to original rotation (Controller Input)

Discussion in 'Input System' started by Trosh_, Jan 19, 2023.

  1. Trosh_

    Trosh_

    Joined:
    May 23, 2022
    Posts:
    1
    Hey, i am trying to make Twin Stick Controller Movement for a Top Down 2D game, i have controller Inputs and movement set up already, but when rotating the character with the right stick, it seems to snap the rotation back, as soon as i let go of the right stick, everything else seems to work just fine, the player rotates correctly with the right stick, just when i stop rotating it, it snaps the rotation back

    here is my code for the rotation:

    Code (CSharp):
    1.  
    2. float RsHorizontal = Input.GetAxis("RSHorizontal");
    3. float RsVertical = Input.GetAxis("RSVertical");
    4.  
    5. if (RsHorizontal != 0 || RsVertical != 0)
    6. {
    7.        float controllerangle = Mathf.Atan2 (RsHorizontal, RsVertical) * Mathf.Rad2Deg - 90;
    8.        rb.MoveRotation(controllerangle);
    9. }
    10.  
    i added the -90 to the rotation angle so the starting position of my sprite would be correct

    any help is appreciated,
    thanks!