I am making a platformer, with a methodical approach to player physics. This is how I do variable jump height:

if not btn(🅾) then
   g_fall *= 1.5

if (not is_grounded) then
   // fall gravity
   p.ay = g_fall

p is the player, p.ay is the acceleration.

g_fall is the constant falling gravity, which I apply to the player's acceleration if it's not on the ground. If the player isn't pressing the jump button I increase g_fall so player falls down quicker thus achieving variable jump height.

This is somewhat ok, but I have a spring where player can jump and it bounces player to the air.

hit.y = ispring.y - 2
hit.dx *= 0.2
hit.dy=-v0_jump * 1.5

hit is the player, v0_jump is the constant initial velocity I give to the player to jump.

When the player presses jump while on the spring, it jumps higher because the fall gravity is lower. But I want spring to give you the same jump height whether you press jump or not.

Now I could put a flag for spring jump and an if condition to test for spring jumps and adjust the fall gravity, but I am looking for a more elegant solution.

So what are some professional techniques for variable jump height that can solve my problem out of the box.

  • 1
    \$\begingroup\$ You may be interested in Building a Better Jump \$\endgroup\$
    – DMGregory
    Jul 28, 2020 at 13:04
  • \$\begingroup\$ @DMGregory There is so much knowledge in those old GDC talks \$\endgroup\$
    – Natalo77
    Jul 28, 2020 at 13:23
  • \$\begingroup\$ I've watched that and that's how I implemented my jump system, and that says to triple the gravity when the jump button isn't pressed which is what I did in my presented solution. \$\endgroup\$
    – eguneys
    Jul 28, 2020 at 14:01


You must log in to answer this question.

Browse other questions tagged .