Thursday, December 27, 2018

2d - How can I find a projectile's launch angle?


I am making a 2d game in which units fire arrows at each other. I know the shooter's and the target's position and the initial velocity of the projectile. I want to know the angle the projectile should have in order to land on the target. The target could be at a different height than the shooter.



To sum up I know v0, R and g and I need to find the angle (or the height ?).


I read http://en.wikipedia.org/wiki/Projectile_motion ,but I can't find something related to what I need.



Answer



The formula to find the angle is


Formula


where v is initial launch speed, g is the gravity constant, x and y are the target's distance and height.


The two roots of this equation give you two possible angles. If the results are imaginary then your initial velocity is not great enough to reach the target (if you want to calculate the angle of reach read this). It's up to you which angle is selected. It would make sense to choose the most direct path i.e. the smaller angle.


You can see a GIF of this equation below with different target values and a constant launch velocity.


Formula graphed as animated GIF


Resources from this wikipedia article



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...