angle to shoot a projectile to hit a target

Started by
2 comments, last by BlackWind 12 years, 3 months ago
Hi,

Can someone help me with the math involved to get the angle at which an static turret should shoot a bullet with constant velocity in order to hit a target with constant velocity? In 2d, without taking into account external forces (no gravity, no friction, etc..)

For example,
*target being at d(0,20) and moving at constant velocity of 10 m/s to east (only in X axis)
*static object being at d(0,0), which can shoot a bullet with also constant velocity 15 m/s

i dont want code, only the math.

thank you in advance.
Advertisement
ok i dont know why i thought i was the first person with this question in the forum. Doing some search i found a lot of topics with the same question. I'm going to take a look and if i have questions i will come back to post them here. If not, i will just put the equation here *just in case*
By all means you should read those old posts. But since I am bored, I'll answer here too. smile.png

You need to find a time t such that the position of the target at time t is a distance of t*15m/s from the tower.

distance(initial_target_position + t*target_velocity - turret_position) = t*bullet_speed

distance(initial_target_position + t*target_velocity - turret_position)^2 = t^2*bullet_speed^2

Now expand the square of the distance as the dot product of the vector with itself, group all the resulting terms by the power of t they have and you'll have a second-degree equation in t. Once you find a positive solution to that equation, you know the target will be at initial_target_position + t*target_velocity, so just point there and shoot.
thank you alvaro!

reading the forums i found one very cool post from you explaining all the math.
http://www.gamedev.n...ost__p__3663387

I knew i had to find the time where 2 distances were equal, and now that i compare my equation with yours, i notice was taking the wrong way since I was comparing the distance from the turret to the "final" target pos .... ¬¬). Also your way is faster because i was using sins and cosines tongue.png

thank you!!

This topic is closed to new replies.

Advertisement