I'm making a tower defense game where the towers are shooting projectiles at enemies. I do not want to make the projectiles homing, and I want to make sure that when a tower fires a projectile, it will hit where the enemy is going to be, instead of firing at where the enemy is currently located.

My givens are the position and velocity of the enemy, the position of the tower and the speed at which projectiles travel. There is no acceleration.

I was considering taking the distance between the tower and the enemy, calculating how long it would take the projectile to connect with the enemy, and then using that to calculate the future position of the enemy, firing at that instead. However, now the distance between my tower and the enemy in the future might be different, so my calculation isn't going to be precise, and it might miss.

How do I correctly calculate where to fire the projectile so that it will always connect with the moving enemy?

  • \$\begingroup\$ does your projectile have to move in a straight line? \$\endgroup\$ – Chachmu Jun 18 '13 at 21:09
  • 1
    \$\begingroup\$ Yes. Also, this question was pointed out to me -- pretty sure my question is a duplicate of that. \$\endgroup\$ – Mana Jun 18 '13 at 21:10

Browse other questions tagged or ask your own question.