- Home /
Character rotation help needed.
I'm making a platformer game with A and D as the controls for left and right navigation. When the player presses the "A" key the character is supposed to rotate 180 degrees from their current facing point and start moving in the other direction(left), however the code does the rotation but the character ends up going backwards (facing left but going right)
I cant seem to figure out how to fix it any help would be awesome. the code that I'm using to handle the rotation is:
if (Input.GetKeyDown (KeyCode.A))
{
transform.Rotate(0,180,0);
}
Answer by sparkzbarca · Nov 21, 2012 at 06:59 AM
if (Input.GetKeyDown (KeyCode.A))
{
transform.Rotate(0,180,0);
transform.position += transform.forward * speed;
}
you should always move relative to the local forward and up and right to make sure you dont end up going the wrong way. I.E. when you rotate the front doesnt become the back because forward rotates with you.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Rotate to facing direction 6 Answers
Quaternion.FromToRotation misunderstanding 2 Answers
Rotating towards the mouse. 0 Answers