Advertisement

Asteroids Ship Rotation

Started by July 25, 2003 02:03 AM
3 comments, last by Aggrix 21 years, 6 months ago
I am struck on getting my ship to rotate like in the original Asteroids. Right now, my ship rotates more like a car. Instead of being able to rotate and not change direction until it accelerates, it turns in a circle. Can anyone help me with this?
Instead of having your ship move forward every frame, store its speed in the X and Y directions in seperate variables and increment its X and Y position by the values of those variables every frame. Implementing thrust will be a bit more difficult, but it shouldn''t be too much of a problem if you know your trigonometry.
Advertisement
do something like

if(thrust){
velx += (float)sin(facing) * THRUST_AMOUNT;
vely -= (float)cos(facing) * THRUST_AMOUNT;
}

Position_x += vel_x;
Position_y += vel_y;

thrust = FALSE;
Are you rotating the ship around it''s centre? The only reason it would be turning in a circle is if the point of rotation is not the centre point of the ship.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
quote:

Origionaly posted by JY:
Are you rotating the ship around it''s centre? The only reason it would be turning in a circle is if the point of rotation is not the centre point of the ship.



That is exactly right. You need to store the ships vertices around the origen (0, 0). For example: A ship that looks like a triangle would have vertices (0, 1), (1, -1), (-1, -1). Then you do all your rotation algorithms on those vertices. Once the vertices have been rotated you can then draw the ship by adding the ships "x" and "y" coordinate to the vertices.

This topic is closed to new replies.

Advertisement