1
\$\begingroup\$

I have a 2D object that constantly moving forward (in the direction its facing). So initially its facing right, and moving right, but as the rotation z-axis changes, so should its direction. Most of what I'm finding is based on the Asteroids game physics, but what I'm doing is not like that (I think), I'm not adding force to the object when I want its direction to change. Basically what I'm trying to do have it's X & Y velocity change based on its z rotation value. Here is an example of something similar to what I'm attempting to do:

Moving object

\$\endgroup\$
2
2
\$\begingroup\$

You can compute the direction to move in like this:

direction_vector = {.x = cos(facing_angle), .y = sin(facing_angle)};

Depending on where exactly you define "zero degrees" to be, you might have to swap sin/cos or make one of them negative.

Wikipedia has a nice animation showing the relationships

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.