Sprint
Holding a button while moving makes the character run faster than it walks. Speed builds up and fades at set rates instead of jumping. The button does nothing without a direction, a wall or a tired body ends the sprint, and the sprint speed is a multiple of the walking speed so it is always faster.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Sprint" to my game.
What it should do: A sprint lets the player choose between careful and fast movement. It adds a second gear to the same controls, so the player decides when speed is worth it.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> still
still: Standing
walk: Walking
sprint: Sprinting
slowing: Slowing down
still --> walk: starts walking
still --> sprint: starts sprinting
walk --> still: comes to a stop
walk --> sprint: sprint pressed
sprint --> slowing: let go while fast
sprint --> walk: let go while slow
sprint --> still: wall or stops dead
slowing --> sprint: sprint again
slowing --> walk: slows to walk speed
slowing --> still: wall or stops dead
```
Use these starting values:
- walkSpeed: 4 units/s
- sprintBoost: 1.75
- accel: 24 units/s²
- decel: 30 units/s²
Watch out for these common mistakes:
- The button pressed before moving: Tell your AI: look at the button and the direction on every tick, so that holding the button first and moving second sprints as well.
- Sprinting while standing still: Tell your AI: the sprint button counts only together with a direction.
- Speed that snaps back: Tell your AI: slow down at a set rate toward the walking speed instead of setting it.
- Turning around at full speed: Tell your AI: when the direction reverses, brake through zero at the slowing rate before building up the other way.
- Sprinting into a wall: Tell your AI: when the character is pushed against a wall, set the speed to zero and end the sprint.
- Starting or stopping a sprint in the air: Tell your AI: in the air keep the speed and change nothing. The button counts again on landing.
- A sprint that is not faster: Tell your AI: define the sprint speed as the walking speed times a factor above one.
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
A sprint lets the player choose between careful and fast movement. It adds a second gear to the same controls, so the player decides when speed is worth it.
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
- Standing → Walking: starts walking
- Standing → Sprinting: starts sprinting
- Walking → Standing: comes to a stop
- Walking → Sprinting: sprint pressed
- Sprinting → Slowing down: let go while fast
- Sprinting → Walking: let go while slow
- Sprinting → Standing: wall or stops dead
- Slowing down → Sprinting: sprint again
- Slowing down → Walking: slows to walk speed
- Slowing down → Standing: wall or stops dead
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| walkSpeed | 4 units/s | The speed of walking. About two body lengths per second reads as a calm walk. |
| sprintBoost | 1.75 | The sprint speed as a multiple of the walking speed, so the sprint is always faster. Below 1.5 players barely notice, above 2.5 the level can no longer keep up. |
| accel | 24 units/s² | How fast speed builds up. At this value a sprint from standing takes about 0.3 seconds, quick enough to feel direct and slow enough to feel like effort. |
| decel | 30 units/s² | How fast speed falls when the player lets go, slows or turns. A little above the build-up, so stopping feels firmer than starting. |
What usually goes wrong
The button pressed before moving
A player who holds the sprint button and then pushes a direction gets walking speed, because the game only looked at the button at the moment it was pressed.
Fix: Tell your AI: look at the button and the direction on every tick, so that holding the button first and moving second sprints as well.
Sprinting while standing still
A sprint that counts as running with no direction wastes a stamina meter, plays the running animation on the spot or gives a burst on the first step.
Fix: Tell your AI: the sprint button counts only together with a direction.
Speed that snaps back
If letting go of the button drops the speed to walking at once, the character jerks to a stop in the middle of a run.
Fix: Tell your AI: slow down at a set rate toward the walking speed instead of setting it.
Turning around at full speed
If the speed flips its sign in one tick, a sprinting character reverses instantly and the sprint has no weight.
Fix: Tell your AI: when the direction reverses, brake through zero at the slowing rate before building up the other way.
Sprinting into a wall
The player runs against a wall holding the button, the character stands still but is still counted as sprinting, and a stamina meter keeps draining for nothing.
Fix: Tell your AI: when the character is pushed against a wall, set the speed to zero and end the sprint.
Starting or stopping a sprint in the air
A sprint started in the air gives speed from nowhere, and letting go in the air stops the character in mid-flight. Both break jumps.
Fix: Tell your AI: in the air keep the speed and change nothing. The button counts again on landing.
A sprint that is not faster
When the sprint speed and the walking speed are set separately, a change to one can leave the sprint slower than the walk.
Fix: Tell your AI: define the sprint speed as the walking speed times a factor above one.
How to check it works
- Your character stands still and the player holds the sprint button with no direction. Half a second passes: The character still stands, at speed 0.
- Your character stands still. Hold right for one second: The speed is exactly 4.
- Your character stands still. Hold right and the sprint button for one second: The speed is exactly 7 and the character is sprinting.
- Your character stands still. Hold right and sprint for one tick: The speed is 0.4, not 7.
- The player holds the sprint button for a third of a second with no direction. The player then pushes right: The character sprints at once.
- Your character sprints at speed 7. Let go of the sprint button but keep walking: The speed falls to 6.5 in the first tick and settles at 4 in a few ticks.
- Your character sprints right at speed 7. Push left and keep sprinting: The speed is 6.5 in the first tick, passes through zero, and ends at 7 to the left.
- Your character sprints at speed 7. It runs into a wall while the button is held: The speed is 0 and the sprint ends, and the next tick starts from 0.4.
- Your character sprints at speed 7. The game stops allowing sprints, as when a meter runs out: The sprint ends and the speed falls to the walking speed of 4.
- Your character sprints at speed 7 and jumps. The player lets go of the button and pushes the other way in the air: The speed stays 7 and nothing changes until landing.
- The walking speed is 10 and the factor is at its lowest, 1.2. Sprint for five seconds: The speed ends at 12, above the walking speed.
- Your character sprints and jumps with the button held. It lands: It carries on sprinting at the same speed.
Works well with
- Stamina System: Drain the meter only on ticks where the character really sprints, which this page's code reports as the sprint phase. A wall or standing still then costs nothing. Ask the meter first, then pass its answer in as the game allowing a sprint.
- Crouch Slide: Start a slide from the sprint's speed. A sprint that ends in a slide keeps its speed, which is what makes the slide feel earned.
- Swimming: Use the sprint only on dry ground. In water, the swimming speeds take over, and a held button should do nothing.
- Ladder Climbing: End the sprint when the character grabs a ladder, and do not carry the speed onto it.
Clashes with Coyote Time: A sprint off a ledge with a late jump press carries a lot of speed, so the grace time makes the jump much longer than a standing one. Allow the late jump, but plan gaps for the longest jump a sprint plus grace time can make.
Common questions
what do i tell my ai to add a sprint
Paste this: Add a sprint. Holding the button while pushing a direction moves the character at the walking speed times 1.75, speed builds and fades at set rates instead of jumping, the button does nothing without a direction, and a wall, a tired body or leaving the ground ends or freezes it.
how much faster should sprinting be than walking
Start at about three quarters faster. Under 50 percent faster most players do not notice it, over 150 percent faster and levels have to be built around it.
should the sprint be a toggle or a hold
Hold is easier to learn and cannot get stuck on. If you add a toggle, end it on a stop or a wall, or the player is still sprinting when they do not expect it.
why does my character keep sprinting against a wall
The sprint is decided by the button, not by whether the character really moves. Set the speed to zero and end the sprint when the character is pushed against a wall.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 16 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.
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