Variable-Height Jump
A variable-height jump goes higher the longer the button is held. The jump starts at full speed, and as soon as the button is let go the rise slows to a low speed. A tap gives a short hop, a long press a full jump. Check whether the button is still down, not when it is let go.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Variable-Height Jump" to my game.
What it should do: One button gives the player a whole range of jumps, from a short hop to a full leap, just by how long they hold it. So every jump is in their hands.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> ground
ground: On the ground
full: Full rise
slow: Slow rise
falling: Falling
ground --> full: press and hold
ground --> slow: quick tap
ground --> falling: walks off the edge
full --> slow: button up, or slowing
slow --> falling: reaches the top
falling --> ground: lands
```
Use these starting values:
- jumpSpeed: 12 units/s
- cutSpeed: 4 units/s
- gravity: 32 units/s²
- maxFallSpeed: 20 units/s
Watch out for these common mistakes:
- A quick tap gives a full jump: Tell your AI: start the jump first, then shorten it in the same step.
- The button is already up when the jump starts: Tell your AI: check on every moment of the rise whether the button is still down. See jump buffering for more.
- The short hop changes with the frame rate: Tell your AI: limit the rise to one fixed speed, or add extra gravity that takes the time passed into account.
- Being thrown up gets cut short: Tell your AI: only shorten a rise that came from a jump.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
One button gives the player a whole range of jumps, from a short hop to a full leap, just by how long they hold it. So every jump is in their hands.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- On the ground → Full rise: press and hold
- On the ground → Slow rise: quick tap
- On the ground → Falling: walks off the edge
- Full rise → Slow rise: button up, or slowing
- Slow rise → Falling: reaches the top
- Falling → On the ground: lands
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| jumpSpeed | 12 units/s | How hard the character pushes off. Together with gravity it sets the height of a full jump. |
| cutSpeed | 4 units/s | How fast a jump may still rise once the button is let go. That sets the shortest hop. |
| gravity | 32 units/s² | How fast a rise slows down, so how long the player has to decide. |
| maxFallSpeed | 20 units/s | The fastest the character can fall. |
What usually goes wrong
A quick tap gives a full jump
If the game looks at the button before it starts the jump, a tap that is pressed and let go in the same instant gets the full height. Nothing was rising yet when the game looked.
Fix: Tell your AI: start the jump first, then shorten it in the same step.
The button is already up when the jump starts
A remembered jump can start after the button was let go. If the game only watches for the moment of letting go, that moment never comes, and a quick press gives a full jump.
Fix: Tell your AI: check on every moment of the rise whether the button is still down. See jump buffering for more.
The short hop changes with the frame rate
If the speed is multiplied by a factor on every step the button is up, the height is different at different frame rates.
Fix: Tell your AI: limit the rise to one fixed speed, or add extra gravity that takes the time passed into account.
Being thrown up gets cut short
A spring or a hit from below throws the character up fast while the button is not held, and shortening the rise stops that dead.
Fix: Tell your AI: only shorten a rise that came from a jump.
How to check it works
- Your character stands on the ground. Press jump and hold until the top of the jump: The jump reaches full height.
- Your character stands on the ground. Tap jump as quickly as you can: You get a short hop, well under the full height.
- Your character is rising fast in a jump. Let go of the button: The rise slows down at once, and after that only gravity acts.
- Your character is falling after a jump. Hold the button, then try again without holding it: The fall is the same either way.
- Your character is thrown upward by something other than a jump. Do not touch the button: The character keeps its speed, apart from gravity.
- Your character is in the air. Press jump: Nothing happens.
Works well with
- Jump Buffering: The other way round, a quick press can give a full jump. See jump buffering. Start the jump first, then keep watching whether the button is still down.
- Coyote Time: A jump from the extra moment after a ledge should be just as easy to shorten as one from the ground. Start the jump first, then shorten it.
- Double Jump: An air jump can be shortened the same way. Decide if it should be; a fixed air jump is easier to judge.
Common questions
how do you make a variable height jump
Take off at full speed. While the jump rises and the button is not held, limit the speed to a low value. Gravity then ends the rise early, so a tap gives a short hop.
what do i tell my ai to add variable jump height
Paste this: Make the jump higher the longer the button is held. Start at full speed, and on every moment of the rise check whether the button is still down, not only the moment it is let go. If it is not down, limit the upward speed to a low value.
why does my short hop change with frame rate
Multiplying the speed at every step depends on how many steps there are. Tell your AI to limit the rise to one fixed speed, or to add extra gravity that takes the time passed into account.
how high should a short hop be compared to a full jump
It follows from the two speeds, because height grows with speed squared. A low speed of a third of the take-off speed gives about a ninth of the height.
Where it comes from
Earliest example we could find: Super Mario Bros. (Nintendo) (1985). Jeremy Parish's 2013 analysis says how long the button is held sets the height and length of Mario's jump, and that starting speed also changes it. The 2016 DiGRA paper's history section reports the game as cited for player control of jump height and distance. Nothing opened here documents the behaviour in an earlier game, but no systematic check of earlier games was possible.
- 1985 Super Mario Bros. (Nintendo): Jeremy Parish's 2013 analysis says how long the button is held sets the height and length of Mario's jump, and that starting speed also changes it. The 2016 DiGRA paper's history section reports the game as cited for player control of jump height and distance. Nothing opened here documents the behaviour in an earlier game, but no systematic check of earlier games was possible. [Anatomy of Super Mario: X. Super-sized (Jeremy Parish, The Anatomy of Games, 2013-08-07; archived mirror)][You Say Jump, I Say How High? Operationalising the Game Feel of Jumping (Fasterholdt, Pichlmair, Holmgard, DiGRA/FDG 2016)]
- 1988 Super Mario Bros. / Duck Hunt instruction booklet (Nintendo of America): The official booklet tells players that holding the button longer gives a higher jump. The booklet itself could not be opened; the wording is taken from a MarioWiki user page that quotes and cites it, which is a weak route to a primary document. [User:KamekSans/Projects/Lists of Jump Profiles/List of Jump Profiles (1981-1989) (Super Mario Wiki user page)]
- 2010 Adam Saltsman, 'Tuning Canabalt': A developer's technical write-up explains a held-button jump driven by a timer that also depends on running speed. It is a public account of how such a jump can be built, with the reasoning given by its author. [Tuning Canabalt (Adam Saltsman, Game Developer/Gamasutra blog, 2010-09-29)]
- 2010 Super Mario Bros. development notes, printed in Nintendo's 25th Anniversary Collection book: Undated pre-release planning notes became public when Nintendo printed them, and a December 2010 blog post on GlitterBerri reproduces them. In the English translation, jump height depends on Mario's speed when the button is pressed. The blog says the Japanese original also mentions button input, and contains unresolved placeholders. These notes show planning, not what shipped. [Mario Development Notes (GlitterBerri, 2010-12-19)]
- 2014 Yoann Pignole, 'Platformer controls: how to avoid limpness and rigidity feelings': A developer blog post contrasts a fixed jump with one that can be cut short, argues the difference matters in jump-focused games, and names Super Meat Boy, Mario and Sonic as examples. [Platformer controls: how to avoid limpness and rigidity feelings (Yoann Pignole, Game Developer, 2014-01-03)]
- 2016 Kyle Pittman, 'Math for Game Programmers: Building a Better Jump' (GDC 2016 talk): A GDC talk on building jump trajectories from designer-facing inputs. Its session overview lists height that varies with player input among the non-parabolic cases it covers. Only the overview was read, not the talk. [Math for Game Programmers: Building A Better Jump (Kyle Pittman, Minor Key Games, GDC Vault, GDC 2016)]
What was checked
- 11 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
- The Godot port passes the same tests on the real engine.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it