• 2D
  • Variable jump height with Kinematicbody?

Hey guys. I didn't see a sticky for rules or anything so hopefully this is fine.

I've been rummaging around looking for a solution to my issue of developing a variable jump height with kinematicbody in my sidescroller.

I've searched the forum, developed my own hacky workaround, found some other resources out there but for past versions of Godot, and the kinematicbody demo in Godot doesn't use variable jump height. I don't know if there's a way to get what I'm exactly looking for.

I'm a bit strict on my player controls but I may just accept it for now, to get my game done.

Below is a screenshot of what my workaround looks like. Basically once the spacebar is pressed I increment (charge) my jump_power. Minimum jump_power is 40, increment by 10, limit at 100. Then once spacebar is released, check and apply the limit if needed, so the player doesn't superjump. (I'm a newbie programmer)

This isn't what I want. This only jumps once I release the spacebar. I would like it to jump immediately, then stop accelerating once I release spacebar. With kinematicbody, adjusting the vel.y variable sends it upwards with some force, then physics does the rest, if im correct? Any help would be appreciated.

You are only updating your velocity.y variable AFTER the spacebar is released. You need to do it under is_action_pressed().

Also, are you trying to achieve a jumping system similar to the original Super Mario Bros, in that your jump height is dictated by the length of how long you hold down the jump button? I'm having trouble understanding your exact goal!

I got it. You sent me on the right path though, for sure.

The jump style would be in the vein of Mario Bros, yes. There's other games with this type of mechanic too. Just feels better to have more of a precise jump.

Here's my code with the change as of right now. Still feels a little stiff.

It still doesn't feel the way I want it to, so I'm going to have to continue tweaking it. There's gotta be a simpler way though.

2 months later

What I've always done is change how much gravity is applied when the jump button is held, rather than changing the jump power itself.

Basically, if you press jump, you jump a set height. However, while you're holding jump and vertical velocity is going up, under a certain threshold, the gravity is weaker.

This makes the jump higher and longer if you hold it.