Checkpoints
A checkpoint is a marker in the level that remembers how far the player got. Touch one and it becomes the place to come back to after a death. Only a marker further along replaces the old one, and what was picked up since the last marker is lost with the death.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Checkpoints" to my game.
What it should do: Checkpoints keep a death from costing the whole level. The player risks only the stretch since the last marker, so a hard part can be tried again and again without walking the same easy part each time.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> fresh
fresh: No marker yet
saved: Marker active
respawning: Down, waiting
fresh --> saved: touches a marker
fresh --> respawning: dies
saved --> respawning: dies
respawning --> fresh: back at the start
respawning --> saved: back at the marker
```
Use these starting values:
- respawnDelay: 1.2 s
- graceTime: 1.5 s
Watch out for these common mistakes:
- An earlier marker sends the player back: Tell your AI: give every marker a number in the order of the level, and only accept a marker with a higher number than the active one.
- The same marker pays out twice: Tell your AI: touching the marker that is already active does nothing.
- Dying and touching on the same moment: Tell your AI: check for death first. If the character dies on a tick, a marker or pickup on that tick does not count.
- Coming back next to the danger: Tell your AI: after coming back, ignore hits for a short time. Keep the fall check on, so a marker at the edge of a pit cannot trap the player.
- Pickups come back after a death: Tell your AI: keep a count of safe pickups at each marker, and put back only the pickups collected after it.
- A slow frame skips the wait: Tell your AI: count the wait in seconds and subtract the real time of each tick.
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
Checkpoints keep a death from costing the whole level. The player risks only the stretch since the last marker, so a hard part can be tried again and again without walking the same easy part each time.
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
- No marker yet → Marker active: touches a marker
- No marker yet → Down, waiting: dies
- Marker active → Down, waiting: dies
- Down, waiting → No marker yet: back at the start
- Down, waiting → Marker active: back at the marker
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| respawnDelay | 1.2 s | How long the player waits between dying and coming back. Long enough to see what happened, short enough that trying again feels quick. It is never zero, because a death with no pause looks like a glitch. |
| graceTime | 1.5 s | How long hits do nothing after coming back. Without it the character can come back right next to the thing that just killed it and die again before the player can move. Falling out of the world still counts. |
What usually goes wrong
An earlier marker sends the player back
The player walks back past an old marker and touches it. If every touch counts, the next death sends them back to a spot they left long ago.
Fix: Tell your AI: give every marker a number in the order of the level, and only accept a marker with a higher number than the active one.
The same marker pays out twice
Touching the active marker again banks the loose pickups a second time, or restores things that were already used, so the player can farm it.
Fix: Tell your AI: touching the marker that is already active does nothing.
Dying and touching on the same moment
The player touches a marker on the very tick the character dies. If the marker counts, the player respawns at a place they never reached alive.
Fix: Tell your AI: check for death first. If the character dies on a tick, a marker or pickup on that tick does not count.
Coming back next to the danger
The marker sits close to a trap or an enemy. The character comes back, is hit before the player can react, and dies again in a loop.
Fix: Tell your AI: after coming back, ignore hits for a short time. Keep the fall check on, so a marker at the edge of a pit cannot trap the player.
Pickups come back after a death
Everything in the level resets on a death, so a coin collected before the marker can be collected again. Or the opposite: the coin counts but also reappears.
Fix: Tell your AI: keep a count of safe pickups at each marker, and put back only the pickups collected after it.
A slow frame skips the wait
A slow moment gives one very long tick. If the wait is counted in ticks, the character comes back far too early or the wait changes with the frame rate.
Fix: Tell your AI: count the wait in seconds and subtract the real time of each tick.
How to check it works
- A character at the start of the level. it touches marker number 2: marker 2 is the place to come back to.
- Marker 2 is active. the character falls out of the world: it waits 1.2 seconds, then comes back for exactly one tick at marker 2.
- No marker has been touched. the character dies: it comes back at the start of the level.
- Marker 3 is active. the character touches marker 1: marker 3 stays active and nothing is banked.
- Marker 1 is active and 2 pickups are banked. the character picks up 3 more and touches marker 1 again: the banked count stays 2 and the 3 stay loose.
- 4 loose pickups. the character touches a new marker holding 1 more pickup: 5 are banked and none are loose.
- 4 banked and 3 loose pickups. the character dies and comes back: 4 are still banked and none are loose.
- The character is down and marker 1 is active. marker 4 is touched: marker 1 stays active and nothing is banked.
- The character has just come back. it is hit every tick for one second, and then once more after 1.5 seconds have passed: the first hits change nothing and only the last one kills.
- The character has just come back. it falls out of the world: it dies again at once.
- A character with no marker. it is hit on the same tick it touches marker 2 and picks up 3: it dies, marker 2 does not count and nothing is banked.
- The character was hit and is down. more hits and a fall arrive while it waits: the death count stays at 1.
- The protected time is set to 0. the character comes back and is hit at once: it dies again.
- The character has just died. three ticks of half a second pass: it comes back on the third tick and not before.
Works well with
- Autosave: A marker is a calm, well-chosen moment to write the save. Touching a new marker should ask for a save. Save when a marker is touched.
- Health and Damage: Coming back with almost no health into the same danger just repeats the death. Decide whether a marker restores health. Refill health when the character comes back.
- Invincibility Frames: Show the protection, for example by blinking, so the player knows hits do nothing for a moment. Use the same protection for the protected time after coming back.
- World State Flags: Doors opened or switches flipped since the marker should go back to how they were at the marker. Store what the player changed after the marker apart from what came before.
Common questions
how do i add checkpoints to my game
Paste this: Add checkpoints. Each marker has a number in the order of the level. Touching one with a higher number than the active one makes it the place to come back to. After a death, wait about a second, then put the character at the active marker, or at the start if there is none.
how far apart should checkpoints be
Place one before every part that is hard to survive and one after it, so the player never has to repeat the hard part and the easy part together. As a start, aim for a marker every 30 to 60 seconds of play.
why do my collected coins come back after i die
The level was reset without remembering what you picked up. Keep a count of safe pickups at each marker, and put back only the ones collected after it.
should the character be safe right after coming back
Yes, for a short time, about a second and a half to start. Ignore hits but not falls, so a marker at the edge of a pit cannot trap the player.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 17 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