- Home /
orienting player in one direction
So I'm facinf a little annoying problem since a while and I don't know how to solve it. So basically I want that when I press A or D the player facing left and right, so the rotation value should be y=270 (left) and y=90(right). and i wrote this code:
private void GetInput() { direction = Vector2.zero; Quaternion target = Quaternion.Euler(0, 180, 0); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 50f); if (Input.GetKey(KeyCode.W)) { direction += Vector2.up; facing = "up"; target = Quaternion.Euler(0, 0, 0); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 50f); } if (Input.GetKey(KeyCode.S)) { direction += Vector2.down; facing = "down"; target = Quaternion.Euler(0, 180, 0); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 50f); } if (Input.GetKey(KeyCode.D)) { direction += Vector2.left; facing = "left"; transform.rotation = Quaternion.Euler(0,270,0); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 50f); } if (Input.GetKey(KeyCode.A)) { direction += Vector2.right; facing = "right"; transform.rotation = Quaternion.Euler(0, 90, 0); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 50f); } }
the problem is, it not work. is not turning left and right, but is working ud and down.
Your answer
Follow this Question
Related Questions
relative orientation to initial coordinate system,relative rotation coordinate transformation 0 Answers
My enemy character is not facing the player correctly! 0 Answers
How Do I rotate a Object Based On the player's location? 1 Answer
How to rotatate an array of points(x,z) around origin point(x,z)? 1 Answer
Rotating objects to specific angle 3 Answers