Find meeting point of 2 objects in 2D, knowing (constant) speed and slope

Posted by Axonn on Game Development See other posts from Game Development or by Axonn
Published on 2011-03-07T15:02:06Z Indexed on 2011/03/07 16:19 UTC
Read the original article Hit count: 266

Filed under:

I have a gun which fires a projectile which has to hit an enemy. The problem is that the gun has to be automatic, i.e. - choose the angle in which it has to shoot so that the projectile hits the enemy dead in the center.

It's been a looooong time since school, and my physics skills are a bit rusty, but they're there. I've been thinking to somehow apply the v = d/t formula to find the time needed for the projectile or enemy to reach a certain point. But the problem is that I can't find the common point for both the projectile and enemy. Yes, I can find a certain point for the projectile, and another for the enemy, but I would need lots of tries to find where the point coincides, which is stupid. There has to be a way to link them together but I can't figure it out.

I prepared some drawings and samples:

A simple version of my Flash game, dumbed down to the basics, just some shapes:

http://axonnsd.org/W/P001/MathSandBox.swf - click the mouse anywhere to fire a projectile.

Or, here is an image which describes my problem:

An image which describes my problem

So... who has any ideas about how to find x3/y3 - thus leading me to find the angle in which the weapon has to tilt in order to fire a projectile to meet the enemy?

EDIT

I think it would be clearer if I also mention that I know: the speed of both Enemy and Projectile and the Enemy travels on a straight vertical line.

© Game Development or respective owner

Related posts about 2d-physics