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 end if (not is_grounded) then // fall gravity p.ay = g_fall end
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.