Hello everyone I'm wondering how to make my character face the direction of the arrow keys for example when I press the right arrow key I want my character to face 90 degrees on the Y axis and when I press the down down arrow key he faces 180 degrees but when I press both I want him to face 135 degrees. How would I do this?
asked Oct 21 '11 at 08:34 AM
To get the desired effect, you need to do two things-
first, in your script-
EDIT: Code fixed- now with 100% more sanity.
EDIT EDIT: Code augmented- now doesn't reset angles.
Now, doing it that way will cause your player to smoothly rotate all the way around the axis- which is good under most circumstances, but sometimes you don't want this (retro-inspired movement style, 8-directions). To make it rotate sharply, change the transform.rotation line to
And then instead of using
which returns a 1 or 0 value.
answered Oct 21 '11 at 08:54 AM