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
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.
Resources from this wikipedia article
No comments:
Post a Comment