I have a rigidbody sphere with mass 1 and use gravity set to true

i wanted to add force to the sphere so that it goes distance d and height h (a parabolic path)

Is there an equation to find add force vector ?

I have a rigidbody sphere with mass 1 and use gravity set to true

i wanted to add force to the sphere so that it goes distance d and height h (a parabolic path)

Is there an equation to find add force vector ?

This is the so-called “ballistic trajectory”: an initial velocity is given to the projectile at certain elevation angle, and physics does the rest. The mass doesn’t matter, only the direction and magnitude of the initial velocity, thus it’s better to calculate the velocity vector and assign it directly to **rigidbody.velocity**.

You can split the velocity into two components, vertical and horizontal. The vertical speed is “consumed” linearly by the gravity, and the maximum height is reached when it becomes zero. This allows us to calculate the initial vertical speed:

```
vertSpeed = Mathf.Sqrt(2 * g * maxHeight);
```

The horizontal velocity doesn’t change during the trajectory (we’re not taking air resistance into account), thus the distance can be calculated by:

```
horSpeed = maxDistance / totalTime;
```

The total time depends on the height of the target: if it’s at the same height as the launching point, the total time will be equal to twice the time taken to reach the max height:

```
totalTime = 2 * vertSpeed / g;
```

If in your case the vertical and horizontal directions are the axes Y and X, you can calculate the rigidbody velocity as follows:

```
var g = Physics.gravity.magnitude; // get the gravity value
var vSpeed = Mathf.Sqrt(2 * g * maxHeight); // calculate the vertical speed
var totalTime = 2 * vertSpeed / g; // calculate the total time
var hSpeed = maxDistance / totalTime; // calculate the horizontal speed
rigidbody.velocity = Vector3(hSpeed, vSpeed, 0); // launch the projectile!
```

Aldo:

I think i got some idea why my projectile is not working. When I use your equation for a single rigidbody it is working well.

What i have is 3 rigid bodies connected together with HingeJoints. When I apply your equation to one of the links it is moving very short distance.

What should I do in a situation like this?