If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: Using code tags properly
Always divorce the input gathering from the input processing. Each frame:
- clear temporary input variables
- gather input into those variables
- process those variables only, not the original input
Then when you change inputs, the problem space is much smaller.
For the actual question: You may be able to simply drive transform.forward
(or transform.up
when in 2D) equal to your movement vector.
Otherwise, use Mathf.Atan2() to derive heading from cartesian coordinates:
Sine/Cosine/Atan2 (sin/cos/atan2) and rotational familiarity and conventions