# 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.

• It depends if you want to stick to realistic ballistic curve or is a parabola good enough.
– AB.
Apr 9 '13 at 9:29
• Do you want to include wind? Or any other horizontal acceleration? (It makes the math harder, of course) Apr 9 '13 at 12:52
• possible duplicate of How to make an arrow land at a specific position in 3D world space
– House
Apr 9 '13 at 13:21
• I want to achieve a realistic projectile motion and there is no wind involved. Apr 10 '13 at 11:09

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

• Note that in most cases there are two valid solutions. Assuming no drag or the like max range is attained when the projectile is fired at a 45 degree angle. Going higher OR lower will lower the range--thus unless you need every bit of oomph from your gun there will be both a higher and a lower solution. Apr 10 '13 at 3:26
• You would probably take the angle that has the shortest flight time, which is usually smaller angle (probably always but I'm allowing myself the possibility of being wrong gracefully heh). It's faster to shoot at the ground in front of your feet by aiming down than by aiming up at a really steep angle. Apr 10 '13 at 5:38
• @StephenTierney Thank you for the answer. This is what I was looking for. Apr 10 '13 at 11:09
• Found a much simpler solution to this problem, info from en.wikipedia.org/wiki/… Apr 11 '13 at 2:18

Earlier this year I created a simple top down shooter. I used the following method:

public static class Helper_Direction
{

// Rotates one object to face another object (or position)
public static double FaceObject(Vector2 position, Vector2 target)
{
return (Math.Atan2(position.Y - target.Y, position.X - target.X) * (180 / Math.PI));
}

// Creates a Vector2 to use when moving object from position to a target, with a given speed
public static Vector2 MoveTowards(Vector2 position, Vector2 target, float speed)
{
double direction = (float)(Math.Atan2(target.Y - position.Y, target.X - position.X) * 180 / Math.PI);

Vector2 move = new Vector2(0, 0);

move.X = (float)Math.Cos(direction * Math.PI/180) * speed;
move.Y = (float)Math.Sin(direction * Math.PI / 180) * speed;

return move;
}
}


It calculates a trajectory between two positions.