Jumping a specific height using Velocity & Gravity

Hello,

I am trying to get my character to jump a specific height using velocity and gravity.

Gravity is currently set to X:0,Y:-20

But, what is gravity? does the -20 mean it is applying a -20 unit velocity per second? This is all I can assume.

Anyway, to keep it simple, lets say I want to jump up 10.0 units. By this, I mean, from the character’s position on the ground, to the peak of his jump, he should have moved 10.0 units.

However, I am pretty bad at the maths. So, gravity is -20 units, I need to peak a jump at 10 units. What velocity would I require?

rigidbody2D.velocity = new Vector2 (0, What goes Here?);

Of course, I am after the equation required, not just the number for 10 units. The character would need to jump 2 units, 5.5 units, 34.44 units, etc.

From: Acceleration - Wikipedia

Using the 3rd formula you can allienate v0 when v is equal to 0, when the object is on its maximum height.

v0 = sqrt(-2 * a * s)

Which in unity would be something like:

float jumpHeight = 10.0f;
rigidbody2D.velocity = new Vector2(0, Mathf.Sqrt(-2.0f * Physics2D.gravity.y * jumpHeight));

This will make the object reach quite close to the jumpHeight, but you have to understand that the physics simulation is not deterministic and will not * exactly * make the object reach your height, but it will be pretty aproximate.

That is always that you have no drag.