-2
\$\begingroup\$

In my game you are controlling a person walking(X and Y) and they can:

Rotate view - -180 to +180
Move a direction - Forward, Backwards, Left, Right.

I want the Move to get closer to a goal position by using the Forward, Backward, Left and Right. https://i.stack.imgur.com/OcDr1.png

The player can be looking anywhere on the -180 to 180 rotation and the direction of the Forward, Backward, Left and Right is changed by Rotation.

\$\endgroup\$
2

1 Answer 1

2
\$\begingroup\$

So your problem is: You have 4 different directions (vectors) and you want to make a linear combination of them, to reach some point "x". Observation 1: You can make that in 2D using only 2 directions (vectors), (for math people: marix rank is 2).

So first, choose 2 linearly independent vectors (Forward - (1,0), Right - (0,1)) and rotate them with your rotation (multiply with rotation matrix).

Then, all you have to do is solve the system of 2 linear equations with 2 variables. You can probably write that in 1 line of code.

Another way is to rotate your point "x" with negative rotation, then you will get the solution straight away.

\$\endgroup\$
1
  • \$\begingroup\$ The point was that you can't control the rotation of the player only the movement. \$\endgroup\$
    – user25810
    Feb 1, 2013 at 6:32

Not the answer you're looking for? Browse other questions tagged .