Parry
A parry is a block with a very short window. Press at the right moment and the blow does no damage, the attacker staggers, and a counter opens. Press too early or too late and the blow lands. Missing costs a pause. Holding the button only guards, and takes part of the damage.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Parry" to my game.
What it should do: A parry rewards close attention. Reading an enemy's attack and answering it at the last moment feels better than running away from it, and it turns defence into the start of an attack.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> ready
ready: Ready
parrying: Parry window
guarding: Guarding
recovering: Recovering
riposte: Counter chance
ready --> parrying: presses parry
ready --> riposte: blow on the press
parrying --> riposte: blow inside window
parrying --> guarding: window ends, held
parrying --> recovering: window ends, let go
guarding --> recovering: lets go
riposte --> ready: counter chance over
recovering --> ready: pause is over
```
Use these starting values:
- parryWindow: 0.15 s
- whiffRecovery: 0.5 s
- lowerTime: 0.2 s
- riposteTime: 0.8 s
- guardShare: 0.3 x
- staggerTime: 0.8 s
- riposteMultiplier: 2 x
Watch out for these common mistakes:
- Holding the button always parries: Tell your AI: a window opens only on the tick where the button goes from up to down, and holding only guards.
- Mashing beats everything: Tell your AI: a press that parried nothing starts a pause in which no new press counts. The same goes for letting go of a guard.
- The window is counted in frames: Tell your AI: measure the window in seconds and count down with the time each frame took. The press frame itself counts.
- Attacks that cannot be parried: Tell your AI: a blow that cannot be parried is treated as a hit against a guard while the window is open, and the window stays open for the next blow.
- A blow that does no damage: Tell your AI: only a blow with damage above zero can be parried, and anything else leaves the window as it was.
- Two blows at once: Tell your AI: decide it on purpose. Here, a parry answers one blow, and the counter chance does not protect the player from the next 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 parry rewards close attention. Reading an enemy's attack and answering it at the last moment feels better than running away from it, and it turns defence into the start of an attack.
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
- Ready → Parry window: presses parry
- Ready → Counter chance: blow on the press
- Parry window → Counter chance: blow inside window
- Parry window → Guarding: window ends, held
- Parry window → Recovering: window ends, let go
- Guarding → Recovering: lets go
- Counter chance → Ready: counter chance over
- Recovering → Ready: pause is over
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| parryWindow | 0.15 s | How long after the press a blow counts as parried. Nine frames at 60 per second. Under 0.08 seconds only experts will manage it, and over 0.3 the parry stops being a skill. |
| whiffRecovery | 0.5 s | The pause after a press that parried nothing. It is the price of guessing. Without it, mashing the button would beat every attack. |
| lowerTime | 0.2 s | The short pause after letting go of a held guard. It stops the player from switching the guard on and off to get a fresh window all the time. |
| riposteTime | 0.8 s | How long the counter chance lasts after a parry. Long enough to turn around and strike, short enough that the enemy is up again before the player dawdles. |
| guardShare | 0.3 x | The share of a blow that still gets through a held guard. Guarding must help, or nobody holds the button, but it must hurt more than a parry, or nobody learns the parry. |
| staggerTime | 0.8 s | How long a parried attacker is thrown off. It should match the counter chance, so the counter always lands on a stunned enemy. |
| riposteMultiplier | 2 x | How much harder the counter hits. The bonus is what makes the risk of a parry worth taking. |
What usually goes wrong
Holding the button always parries
The code asks whether the button is down, not whether it was just pressed. A player who holds it is covered every moment and never has to time anything.
Fix: Tell your AI: a window opens only on the tick where the button goes from up to down, and holding only guards.
Mashing beats everything
A player taps the button as fast as they can. With no price for missing, a window is open almost the whole time, and the skill is gone.
Fix: Tell your AI: a press that parried nothing starts a pause in which no new press counts. The same goes for letting go of a guard.
The window is counted in frames
A window of 9 frames lasts 0.15 seconds at 60 frames per second, but 0.3 on a slow device, so the same game is easier on the worse machine.
Fix: Tell your AI: measure the window in seconds and count down with the time each frame took. The press frame itself counts.
Attacks that cannot be parried
Some enemy attacks are marked as unstoppable. If the window turns them aside anyway, the mark means nothing, and if the window swallows the blow without any effect the player is hit in full.
Fix: Tell your AI: a blow that cannot be parried is treated as a hit against a guard while the window is open, and the window stays open for the next blow.
A blow that does no damage
A push or a slowing effect with no damage arrives while the window is open. The code reads it as a hit, the parry fires, and the real blow a moment later hits the player in full.
Fix: Tell your AI: only a blow with damage above zero can be parried, and anything else leaves the window as it was.
Two blows at once
Two enemies strike in the same moment, or one attack has several hits. One parry cannot answer both, but a game that shields the player from all of them makes the parry far too strong.
Fix: Tell your AI: decide it on purpose. Here, a parry answers one blow, and the counter chance does not protect the player from the next one.
How to check it works
- The player presses parry and a blow of 20 arrives 5 frames later. the blow lands: the player takes 0, the attacker is staggered for 0.8 seconds, and the counter chance opens.
- A blow of 20 arrives on the very frame the player presses. the frame is worked out: the blow is parried.
- The player presses parry once and lets go. a blow arrives on the 9th frame, and another test on the 10th: the 9th is parried and the 10th hits in full.
- The player presses parry and keeps holding it. a blow of 20 arrives after the window: the player takes 6, which is 30 percent.
- The player taps parry and nothing hits. they press again during the next half second: the press does nothing, a blow in that time hits in full, and the player is ready after 0.5 seconds.
- The button was already held when the fight started. a blow of 20 arrives: the player takes 20 and no window opens.
- A parry has just worked. the counter chance runs, and then runs out: the next blow does 2 times the damage for 0.8 seconds, and 1 times after that.
- The window is open. a blow of 20 that cannot be parried arrives, and then one that can: the first costs 6 and the window stays open, and the second is parried.
- The window is open. a blow of 0, of -5 or of a value that is not a number arrives: nothing is parried, nothing is taken, and the window goes on.
- A parry has just worked. a second blow of 20 arrives during the counter chance: the player takes 20.
- The player is guarding with a held button. they let go and press again at once: the press opens no new window for 0.2 seconds.
Works well with
- Hitbox and Hurtbox: The boxes say that a blow landed. The parry decides how much of it counts. Never change the boxes to make a parry work. Find the hit first, then ask the defender what happens.
- Knockback: A parried blow pushes the attacker back or off balance, and a guarded blow slides the defender. A blow in full pushes as usual. Stagger the attacker, and push the player only for a guarded blow.
- Stamina System: A parry or a guard can cost stamina, and a guarded blow can drain more. Refuse the press when the bar cannot pay, like any other move. Take the price when the window opens.
- Health and Damage: Health takes the amount the parry lets through, which is zero, a share or the whole blow. Pass the damage through the parry, and only then to health.
Clashes with Dodge Roll: Both answer an incoming blow with the same kind of timing, so the player picks one and ignores the other. Give them different jobs. A roll moves the player out of the way of any blow, and a parry earns a counter from one blow it can answer. Mark some attacks as parryable only and some as rollable only.
Common questions
how does a parry work in a game
The player presses a button, and for a very short window a blow that lands is turned aside completely. Outside the window it hits as usual. A good parry also staggers the attacker.
how long should a parry window be
Start with 0.15 seconds, which is nine frames at 60 per second. Much shorter is only for experts, and much longer takes the skill out of it.
how do i stop players from spamming parry
Give a press that parried nothing a pause, and give letting go of a held guard a shorter one. Then guessing costs something and the timing counts.
what do i tell my ai to add a parry
Paste this: Add a parry. A new press opens a window of 0.15 seconds. A blow with damage that lands in it does nothing, staggers the attacker for 0.8 seconds and opens a counter chance of 0.8 seconds at double damage. A missed press causes a pause of 0.5 seconds. Holding the button guards and lets 30 percent through. Holding never opens a window.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 18 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