How would I go about making an object move (or apear to move) in all 360 degree directions. I am thinking of creating a top down game where the left and right arrows would rotate a spaceship left and right while up would move it in the direction it's facing. I'm not sure of the best way to do this I know I can get eight directions like this
up = y-1
up/right = y-1 x+1
right = x+1
right/down = y+1 x+1

so the problem is that too add more directions I would have to make the spaceship move more pixels at time and mabye that would make the movement jerky, and I'm not sure the way I'm doing it is the best way. Dose anyone have a better way to move in 360ish directions?
Posted on 2002-03-19 14:24:06 by Quantum
Hi !

Don't be afraid of the fraction numbers. just take the coords as floating point numbers and give them rounded to integer values to the plotting-procedure.
For the movement you can use a 2x2 rotation-matrix

/ \
| Cos phi -Sin phi \
| |
| Sin phi Cos phi |
\ /

where phi is the direction angle (0 and Pi (=180?) for horizontal movement and Pi/2 and 3 Pi / 2 (= 90? and 270?) for vertical movement. Then get your adding movement-vector by the velocity v multiplied with a base vector (e = (1, 0)) with the rotationmatrix above applied.

an example:

velocity is 1.5,

base-vector is e = (x = 1, y = 0),

angle is 0.5 Pi

rotation-matrix is then

/ \
| Cos (0.5 Pi) -Sin (0.5 Pi) |
| | = R
| Sin (0.5 Pi) Cos (0.5 Pi) |
\ /

the coordinates of the ship are (PX , PY).

You will get the new position (PX', PY') by calculating

(PX', PY') = (PX, PY) + v * R * e <- R*e is a matrix-product !!!

Hope this helps you, greetings, CALEB
Posted on 2002-03-19 15:36:50 by Caleb