Shots in different directions - assign correct velocity

This one is pretty simple, and it’s found in many games. :persecutioncomplex: The simplest one being asteroids.
The ship is rotating, and shooting - but how do I find out how much X/Y-velocity I need to assign a bullet, in order for it to fly as if it
was shot from the nose of the ship?

Thanks in advance :slight_smile:

How about sin and cos.
dX = cos(angle in radians)
dY = sin(angle in radians)

Then you can add your vehicle velocities to ammo velocities. Also you should count law of conservation of linear momentum for realism.

dY = cos(angle in radians)
Right? Or both sin? :o

dX = cos(angle in radians)
dY = sin(angle in radians)

I’ve just started looking at this, this morning (never learned this in school - I’m 16).
Now, due to wonderful articles on the interwebs the learning of those two functions were smooth. In located in Denmark though, so the technical terms is different. Radian.

That is called “angle” here… I think. Is it correct to say theres 360 radian in a circle?
A flat line has 180 radian? Never heard the term before, in english.

EDIT: Just looked it up. Appearently, 0 radian is a flat line. Does Java measure rotations in radian or degrees then?

Full circle is 2*pi radians or 360 degrees.
http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Math.html#sin(double)
Javadocs for sin and cos. If you are unfamiliar with radians use toRadians and toDegrees functions.

a trick i used when i developed an asteroids clone is to advance the position of the bullet by 2 or 3 frames harcoded so that it has reached the ships perimeter