1
\$\begingroup\$

I'm working on a top down space shooter and am having trouble with calculating/understanding the physics for projectiles launched from the space ship.

The ships have a velocity vector and a turret with rotation independent from the body of the ship. Currently projectiles are launched based on the turrets rotation by making a normalized vector then multiplying each component by a speed. However, this doesn't work when the ship is moving faster than the speed scalar.

Right now if the ship is going faster than the projectile speed scalar and the turret is aimed in the same direction as the ship's velocity, the projectile goes backwards (away) from the ship. Assuming there is no drag/gravity (very deep space), how should I go about handling projectiles?

\$\endgroup\$
1

1 Answer 1

5
\$\begingroup\$

The velocity of a projectile fired from a moving vehicle should be vehicleVelocity + projectileVelocity.

So whatever velocity you would give your projectiles if the ship wasn't moving, should be added to the ship's velocity. This is true regardless of the direction it was fired.

So from the point of view of someone standing still, a projectile fired forward would go faster than a projectile fired behind. However, from the point of view of the ship, they both travel away from the ship at the same speed. (Further reading: Frame of Reference)

This only changes when you get get much closer to the speed of light, but I don't think you'll have that problem :)

\$\endgroup\$
1
  • \$\begingroup\$ This is definitely the phyiscally-correct way to do it. However, I'll just note that for some games, it's more "fun" for the player if missile velocity is "reset" to just its own velocity. That way, when placing your crosshair on an immobile target, you can shoot directly facing it knowing your missile will eventually reach it. This does cause some conflicts if players/characters themselves move around pretty fast, like in the question's instance. \$\endgroup\$
    – Katana314
    Commented Jul 9, 2013 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .