1

I am making a game in C# in unity where the player uses an Xbox 360 controller to control a character, I can rotate the player easily like this using the right joystick:


if(Input.GetAxis("RightJoystickX")!=0 && Input.GetAxis("RightJoystickY")!=0)
        {
            float horizontal = Input.GetAxis("RightJoystickX") * Time.deltaTime;
            float vertical = Input.GetAxis("RightJoystickY") * Time.deltaTime;
            float angle = Mathf.Atan2(vertical, horizontal) * Mathf.Rad2Deg; 

            characterController.transform.eulerAngles = new Vector3(0, newAngle, 0);
        }

however, every time I release the joystick and then move it again, it immediately jumps to that new position and doesn't add the rotation to the previous rotation. This is a problem as the player can only move forwards in the direction the character is rotation, i need to be able to add rotations to the previous state without jumping to a new rotation.

  • 1
    You set `newAngle` as the new direction but you don't show the code that set `newAngle`'s value... So it will be kinda hard to help you out without more code. Or maybe you meant to set `angle` instead of `newAngle`? Anyway for Unity related questions you might want to try http://answers.unity3d.com/ – Ronen Ness Aug 07 '16 at 23:18
  • http://answers.unity3d.com/answers/777764/view.html ? – OmegaExtern Aug 07 '16 at 23:20
  • it is meant to be angle not new angle, the problem is when i stop rotating and then rotate again, the new rotation isn't relative to the old rotation – James Clarke Aug 08 '16 at 13:35

0 Answers0