❔ Need help trying to make 2D car move from above
With this code I can only move it up and rotate left 90 degrees. I want to be able of rotating it 90 degrees left and then when I press W it keeps moving in the left direction. Some kind of forward code
5 Replies
You gotta change the directional vector. Which admittedly doesn't directly exist for you right now.
in 2D, the next position for a movement can be described as
x' = x + directionalVector * velocity
So when you press A, your directional vector also needs to rotate by 90°
Ok
So what do I change it to?
That's Unity, right? Not sure if there's a more elegant way, but I'd just store a Vector2 in that class and everytime I press A, it rotates by 90°. then, instead of using
Vector2.up
, you use that new vectorIt is Unity yes
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.