- Home /
Question by
CursedEntity · Apr 25, 2018 at 01:22 PM ·
2d gamejoystickrotation axisxbox controller
2D top down rotation with Xbox Right Joystick
I'm making a 2D Top down rhythm 2 player game where players use Xbox controllers to move, aim and shoot.
Right now when the player tries to look up directly 90 or -90 degrees the rotation does not follow, it automatically goes a bit to the left or to the right. If you look horizontally it moves as it should.
Here's the code for rotation:
float RotationH = Input.GetAxisRaw("RightStickHorizontal") * Time.deltaTime * maxRotation; // Gets the horizontal axis of the controller multiplied by time delta time and float max rotation speed;
float RotationV = Input.GetAxisRaw("RightStickVertical") * Time.deltaTime * maxRotation; //Gets Vertical axis.
//Debug.Log(Input.GetAxisRaw("RightStickHorizontal"));
float angle = Mathf.Atan2(RotationH, RotationV); //create float angle which gets the angle of each rotation variable, and changes the radius to degrees
//Debug.Log(angle);
//Quaternion target = Quaternion.Euler(0, 0, angle); //target rotation is the angle of the right joy stick
transform.rotation = Quaternion.Euler(0f, 0f, angle * Mathf.Rad2Deg);
Comment
Your answer