I have a very basic Asteroids-ish demo. At the moment, no matter how fast the velocity of the ship is, the missiles travel at a constant velocity: -
missile_velocity = new Vector2D(MISSILE_SPEED, MISSILE_SPEED);
Now, if the ship was always facing in the direction of motion when firing, it would be simple enough with: -
missile_velocity = new Vector2D(MISSILE_SPEED + theShip.getVX(), MISSILE_SPEED + theShip.getVY());
But…since this is Asteroids-alike, the ship could be travelling in one direction and facing in another direction, which leads to very odd results - such as if the ship was facing 180 degrees of the direction of travel, the missile speed is still MISSILE_SPEED + Ship Speed when I assume it should be either a steady rate or halved.
So, what to do? My math isn’t great. The ship’s motion is worked out with: -
if (isThrusting) {
acceleration.x = THRUST_POWER * theMechanics.cosLookupTable[(int)angle - 1];
acceleration.y = THRUST_POWER * theMechanics.sinLookupTable[(int)angle - 1];
} else {
acceleration.x = 0.0;
acceleration.y = 0.0;
}
velocity.x += acceleration.x;
velocity.y += acceleration.y;
position.x += velocity.x;
position.y += velocity.y;
Any help would be great