Jump to content
  • Advertisement
Sign in to follow this  
BlackWind

angle to shoot a projectile to hit a target

This topic is 2522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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*

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!