• Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

# angle to shoot a projectile to hit a target

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1BlackWind  Members   -  Reputation: 196

Like
0Likes
Like

Posted 14 January 2012 - 06:25 PM

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.

### #2BlackWind  Members   -  Reputation: 196

Like
0Likes
Like

Posted 14 January 2012 - 07:54 PM

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*

### #3Álvaro  Members   -  Reputation: 5795

Like
1Likes
Like

Posted 14 January 2012 - 11:31 PM

By all means you should read those old posts. But since I am bored, I'll answer here too.

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.

### #4BlackWind  Members   -  Reputation: 196

Like
0Likes
Like

Posted 15 January 2012 - 09:33 AM

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

thank you!!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS