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:
\$\begingroup\$
\$\endgroup\$
2
-
\$\begingroup\$ Does this answer your question? How do I make an entity move in a direction? \$\endgroup\$– Jonathan S.Commented May 16, 2021 at 17:03
-
\$\begingroup\$ Are you working in Unity, or a different framework/engine? \$\endgroup\$– DMGregory ♦Commented May 16, 2021 at 17:12
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
0
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.