I think you are confusing some things here... If you want that the bullet keeps on flying on the initial line, you either have to save the angle or the x and y speed, when you instance your bullet.
When you don't want the bullets to be able to change direction or speed, you can precalculate x and y speed and just update with those values.
this is the update method in one of my prototypes:
1 2 3 4 5
| public void updateDistance(int d) { xd = (float) (-Math.sin((r*Math.PI / 180)) * ys * d); yd = (float) (Math.cos((r*Math.PI / 180)) * ys * d); } |
the parameter d is the time delta in milliseconds since last update.
ys defines the speed
r is the rotation (float from 0-360, where 0 is pointing to the top/north)
xd and yd are the traveled distance in this frame.
if you want to precalculate, you would have to remove the "* d" from both formulas and then apply the delta during update.
I hope this helps. there may be a better solution (there most certainly is, as I'm not really that strong in math).
one additional thing you need is the angle. i calculate the angle (r := radius) like this
1 2 3 4 5 6 7 8
| public static float getAngle(float x0, float y0, float x1, float y1) { float f1 = (float)Math.toDegrees( Math.atan2( y0-y1, x0-x1 ) ); f1+=270; while ( f1 > 360 ) f1-=360; while ( f1 < 0 ) f1+=360; return f1; } |
Simply use the bullet spawn coordinates for x0 and y0 and the current player coordinates for x1 and y1.