Gradual Jump

Hi,

I am trying to figure out how to get my character to jump like this: - YouTube

Of course, when I use jump, I use Input.GetButtonDown. This does not allow me to lerp the jump and allow for a gradual ascent.

How can I go about doing this with gravity ( which I have added with a simple inAirVelocity.y -= gravity * Time.deltatime )

Thanks!

Usual (real world) jumping is always a constant parabola. The height is specified by the strength of the jump. In the real world you can’t accelerate in air :wink:

In games it’s hard to input the desired strength with digital buttons. That’s why you usually accelerate over time as long as the button is held down. A fix-height-jump is usually done by adding a one time y-speed-boost and let the gravity bring the player back down.

For gradual acceleration i would split the behaviour into jumping (without gravity) and the normal falling phase. While jumping you start with a fix y speed which decreases while you gain height until you reach the max-jump height, at which your decrease should reach a speed of 0, or when you release the jump button. When the jumping part is over you turn gravity back on and let him decelerate the left over speed and then he will fall normally.

If you want to keep the same curve downwards when you keep pressing the jump button (some kind of gliding) you wouls just do the same which you’ve done for jumping up just reverse ov course :wink:

It’s probably a bit of try and error to get good values but it should be possible that way.

The easiest way to implement this is to just reduce the gravity while you hold the jump button. That way you perform a longer and higher jump but when you release the button the normal gravity is restored and you fall quicker which shorten the jump.

Of course you have to check that the player has left the ground so he can’t glide again after he released the jump button unless that’s what you want.