Spielerando

Invincibility Frames

Invincibility frames are a short stretch of protection after a hit lands. While it lasts, further hits change nothing, so one touch cannot drain the character in a blink. Measure the protection in seconds, not screen frames, never let it restart on ignored hits, and let pits and crushing traps ignore it.

Also called: I-frames, Hit protection, Damage immunity window, Post-hit invulnerability.

A small otter mechanic in a shimmering shell flickers as a second brass pendulum swings straight through the spot where it was just hit, in a workshop made of layered coloured paper.
Quillcog Yard, an invented papercraft workshop adventure. Invented game, image generated with AI.

Paste this to your AI

Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.

Add "Invincibility Frames" to my game.

What it should do: Protection after a hit gives the player time to get away, and it stops a character standing in a hazard from losing all its health in a fraction of a second. Done wrong it is either too short to matter or so long that danger stops feeling real.

Build it exactly as this state machine. First check that it fits my game, then build it like this:

```mermaid
stateDiagram-v2
  [*] --> vulnerable
  vulnerable: Open to hits
  protected: Protected
  down: Down
  vulnerable --> vulnerable: no hit
  vulnerable --> protected: takes a hit
  vulnerable --> down: hit takes the last health
  protected --> protected: hits are ignored
  protected --> vulnerable: protection runs out
  protected --> down: piercing hit finishes
  down --> down: stays down
  down --> [*]
```

Use these starting values:
- maxHealth: 6
- protectTime: 1 s
- flickerRate: 10 1/s

Watch out for these common mistakes:
- Counting screen frames instead of seconds: Tell your AI: keep the protection in seconds and take the time since the last tick off it.
- An ignored hit restarts the window: Tell your AI: a hit that is ignored changes nothing at all, so the window ends on time and the next hit lands on time.
- Pits and crushing traps: Tell your AI: give these hazards a piercing hit that ignores protection and leaves the window as it was.
- The flicker decides the hit: Tell your AI: decide hits from the time left only, and draw the flicker from the time left as a separate step.
- A hit in the moment the window ends: Tell your AI: let time pass first, then decide on the hit.
- Overkill and healing from the ground: Tell your AI: report only the health actually taken off, and ignore healing once the character is down.

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

Protection after a hit gives the player time to get away, and it stops a character standing in a hazard from losing all its health in a fraction of a second. Done wrong it is either too short to matter or so long that danger stops feeling real.

How it runs, as a diagram

Everything it can be in, and what moves it on. Your AI builds from exactly this.

no hittakes a hithit takes the last healthhits are ignoredprotection runs outpiercing hit finishesstays downOpen to hitsProtectedDown
How it runs, as a diagram
  • Open to hits → Open to hits: no hit
  • Open to hits → Protected: takes a hit
  • Open to hits → Down: hit takes the last health
  • Protected → Protected: hits are ignored
  • Protected → Open to hits: protection runs out
  • Protected → Down: piercing hit finishes
  • Down → Down: stays down

Good starting values

ValueStart withWhat it changes
maxHealth6The most health the character can have. Six is a small number on purpose: with one point per ordinary hit and a protection window, the player can see every hit coming and count what is left.
protectTime1 sHow long a landed hit protects. One second is enough to walk out of an enemy's reach, and short enough that a character who stays in danger is hit again. Under a quarter second players cannot react, over three they ignore enemies.
flickerRate10 1/sHow often the picture switches between shown and hidden while protected. Ten times a second reads clearly as hurt without hiding where the character is. It changes the picture only, never who can be hit.

What usually goes wrong

Counting screen frames instead of seconds

A protection of 60 frames lasts one second on one screen and under half a second on a fast one. The game gets harder for people with better hardware.

Fix: Tell your AI: keep the protection in seconds and take the time since the last tick off it.

An ignored hit restarts the window

A character standing in a hazard that touches it every tick is hit once, then protected for as long as it stands there, or loses health the moment protection ends and never gets a chance to leave.

Fix: Tell your AI: a hit that is ignored changes nothing at all, so the window ends on time and the next hit lands on time.

Pits and crushing traps

A pit or a crushing wall that respects protection cannot kill a character who was just hit, so the player drops into a hole and survives it.

Fix: Tell your AI: give these hazards a piercing hit that ignores protection and leaves the window as it was.

The flicker decides the hit

If the game checks whether the picture is shown to decide whether a hit lands, the character can be hit during every other short moment of protection.

Fix: Tell your AI: decide hits from the time left only, and draw the flicker from the time left as a separate step.

A hit in the moment the window ends

If the hit is checked before the time is taken off, a hit in the last tick of protection is ignored, and the window seems a tick longer than set.

Fix: Tell your AI: let time pass first, then decide on the hit.

Overkill and healing from the ground

A hit of 900 on a character with 2 health reports 900 damage, and a heal that arrives after the last hit brings the character back up although it was already down.

Fix: Tell your AI: report only the health actually taken off, and ignore healing once the character is down.

How to check it works

Works well with

Common questions

how long should invincibility frames last after a hit

Start with one second for a normal hit. Under a quarter second players cannot react to it, and over three seconds they stop fearing enemies.

why does my character get hit again right after the protection ends

A hazard that touches every tick lands the moment the window closes. That is correct: the protection is for escaping. Give the player time and a way out, such as a push away from the hazard.

should invincibility frames protect from falling into a pit

No. A pit, a crushing wall or any hazard that is meant to end the run should pierce the protection, or the player survives holes just by having been hit a moment before.

what do i tell my ai to add invincibility frames

Paste this: Add one second of protection after a landed hit, counted in seconds and not in screen frames. Ignored hits change nothing and never restart it. Pits and crushing traps pierce it. The flicker is drawn from the time left and never decides a hit.

Where it comes from

We could not find a reliable origin for this one yet.

Where this mechanic comes from has not been researched yet.

Games are named only as references. Names and marks belong to their owners, and nothing here is endorsed by them.

What was checked

This is what separates the blueprint from a catalogue entry: the values on this page come from code that runs.

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