- Home /

# Parabolic Movement Equation Problem?

Alrighty I have the following problem. I've been moding in Warcraft3 Map Editor for quite a long time and decided to start unity and here are parabolic equations that I've used in W3 and that worked flawlessly:

When both targets inital Y heigths are 0 (requires that both targets are grounded aka their y coordinate is 0):

```
float Parabola(float h, float d, float x)
{
return (4 * h / d) * (d - x) * (x / d);
}
```

And the function that takes the initial heights that are different ( for example y0 = 5 and y1 = 0)

```
float ParabolaInitial(float y0, float y1, float h, float d, float x)
{
float A = (2 * (y0 + y1) - 4 * h) / (d * d);
float B = (y1 - y0 - A * d * d) / d;
return A * x * x + B * x + y0;
}
```

where x is the localized coordinate towards target, d is the total distance between targets, h is the max height, and y0,y1 respectively height coordinates of start and end target.

This works but gives me the parabola path that is colored red, while I remember that in W3 i was getting green colored parabola path. Red look great but green is the thing that will totaly look incredible and I'm not sure where I'm making a mistake. Here is the picture:

Does anyone has any other parabolic movement codes?

Thank you in advance.

EDIT:

Oh I forgot to state that the problem is that my target is moving, since I am using this formula to make some of the missiles for ranged units have an arc.

**Answer** by Omberone
·
Jun 30, 2014 at 10:24 AM

Have you had a look at `http://en.wikipedia.org/wiki/Trajectory_of_a_projectile`

?

You need either

a fixed time it will take for it to hit the ground, or

an initial angle of attack of the projectile, or

a fixed muzzle velocity

to be able to calculate the parabola accurately. As you say there are two different (four actually, but we won't bother with the two going below the ground) solutions to the equation, one that takes less time, and one that takes the longer time - with a higher arc. You seem like you know your way around math, so that wiki article should come in handy =) Should you find it difficult to implement it, come back here and let us know.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.