- Home /
Cant get my character to rotate properly
Im working on a mobile game where it has two joysticks and two sets of axis, one for movement and one to handle play rotation and change look direction. Everytime i release the joystick it sets the players rotation to -180 but would rotate properly when moving the joystick. Below is the code i have for the entire player controller.
float _x = CrossPlatformInputManager.GetAxis("Hori");
float _y = CrossPlatformInputManager.GetAxis("Verti");
float x = CrossPlatformInputManager.GetAxis("Horizontal");
float y = CrossPlatformInputManager.GetAxis("Vertical");
Vector3 movement = new Vector3(x, 0, y);
//rb.velocity = movement * speed;
transform.Translate(movement * speed * Time.deltaTime);
anim.SetFloat("VelX", x);
anim.SetFloat("VelY", y);
float yRot = Mathf.Atan2(_x, _y) * Mathf.Rad2Deg;
Debug.Log(yRot);
transform.eulerAngles = new Vector3(transform.eulerAngles.x, yRot, transform.eulerAngles.z);
Is there a better way to handle player rotation? I want the rotation to be seperate from movement and it seems to work well just need to fix this rotation issue. Also.. Its an AR game too so i cant utilize the camera for lookrotation incase anyone was wondering.
Your answer
Follow this Question
Related Questions
Rotation of character resets when joystick is released 3 Answers
Third person Character Controller slowing down when camera is pointing towards the ground 2 Answers
Character Controller change target direction in degree 1 Answer
Camera/Direction Rotation 2 Answers
Shuriken particle trail rotating 1 Answer