Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ,but I can't find something related to what I need.

share|improve this question
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) – Seth Battin Apr 9 '13 at 12:52
I want to achieve a realistic projectile motion and there is no wind involved. – korn3l Apr 10 '13 at 11:09
up vote 10 down vote accepted

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.

Formula graphed as animated GIF

Resources from this wikipedia article

share|improve this answer
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. – Loren Pechtel 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. – Azaral Apr 10 '13 at 5:38
@StephenTierney Thank you for the answer. This is what I was looking for. – korn3l Apr 10 '13 at 11:09
Found a much simpler solution to this problem, info from… – Stephen Tierney Apr 11 '13 at 2:18

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

Earlier answer:

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.