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\$
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 :)

| improve this answer | |
\$\endgroup\$
  • \$\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 Jul 9 '13 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.