# How to make a variable height jump controlled by parameters?

I'm trying to make a variable height jump controlled by parameters. I want to be able to specify the max height of my jump, and a time to max height. I also want to be able to specify a min jump height. My understanding is we construct a jump by using max_height and time_to_max to calculate gravity.

func gravity(height, peak_time):
return -2 * height / pow(peak_time * 2, 2)


Because min_jump_height uses the same gravity as max jump height, it’s time to peak is not determined directly, but through the other variables. I calculate my initial velocity based on my min_jump_height and gravity:

func initial_velocity(gravity, min_height):
return sqrt(2 * -gravity * min_height)


As usual, I apply gravity each frame:

velocity += gravity * delta


How do I make it so that each frame the jump button is held a little more is added to velocity such that the original peak height is hit at peak time? This is, in effect, compensating through interpolation for if my initial velocity had been targeted to my max_height instead of my min_height. I imagine there might be more than one valid form of interpolation to solve this problem and I’d be interested in any of them, but the simplest will do.

• Comments are not for extended discussion; this conversation has been moved to chat. Jun 8 at 18:15