Block and Guard
Block and guard lets a character hold up a guard that cuts down hits from the front. A hit in the first moments after raising it costs nothing, which is a parry. Each block drains a guard meter, and a hit the meter cannot pay for breaks the guard. A short wait after letting go stops free parries from tapping.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Block and Guard" to my game.
What it should do: Guarding gives the player a way to take a hit instead of avoiding it, and the parry rewards good timing. The meter and the break keep it from being a way to stand still forever.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> open
open: Guard down
parry: Parry window
guard: Guarding
lowering: Lowering
broken: Guard broken
open --> parry: raises the guard
parry --> guard: window ends
parry --> lowering: lets go early
guard --> lowering: lets go
guard --> broken: meter too low
lowering --> open: wait is over
broken --> open: break wears off
```
Use these starting values:
- parryWindow: 0.15 s
- guardReduction: 0.8
- guardMeter: 60 units
- meterRegen: 15 units/s
- breakTime: 1.2 s
- lowerTime: 0.3 s
Watch out for these common mistakes:
- Tapping the button for free parries: Tell your AI: after letting go, make the guard wait a short while before it can go up again, and open the parry window only when the guard goes up.
- Guarding hits from behind: Tell your AI: only count a hit as guarded when it comes from the side the character faces. Other hits go through in full and cost no meter.
- A hit the meter cannot pay for: Tell your AI: if the meter is smaller than the hit, let the whole hit through, empty the meter and break the guard. Never let the meter go below zero.
- A press and a hit in the same moment: Tell your AI: decide the tick from how it began. A hit that arrives while the guard is not up is a full hit, even if the press is in the same tick.
- Holding the button through a break: Tell your AI: after a break, wait for the button to be let go once before a new guard can start.
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
Guarding gives the player a way to take a hit instead of avoiding it, and the parry rewards good timing. The meter and the break keep it from being a way to stand still forever.
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
- Guard down → Parry window: raises the guard
- Parry window → Guarding: window ends
- Parry window → Lowering: lets go early
- Guarding → Lowering: lets go
- Guarding → Guard broken: meter too low
- Lowering → Guard down: wait is over
- Guard broken → Guard down: break wears off
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| parryWindow | 0.15 s | How long after raising the guard a hit from the front costs nothing. About a seventh of a second is tight enough to be a skill and wide enough to learn. Longer, and the player simply holds the button down and always parries. |
| guardReduction | 0.8 | The share of a blocked hit that does not get through. Four fifths leaves a little chip damage, so a long guard still wears the player down. At 1 a block costs only meter. |
| guardMeter | 60 units | How much the guard can take before it breaks. Sixty holds about three ordinary hits of twenty, so the player has to look for a gap instead of waiting behind the guard. |
| meterRegen | 15 units/s | How fast the meter fills while the guard is down. Slow enough that a pause matters, fast enough that a good fight never ends with a meter stuck at empty. |
| breakTime | 1.2 s | How long a broken guard leaves the character open. This is the price of letting the meter run out, so it should be long enough for the enemy to make use of it. |
| lowerTime | 0.3 s | The wait after letting go before the guard can go up again. Without it the player taps the button over and over and gets a parry window every time. |
What usually goes wrong
Tapping the button for free parries
If the parry window opens every time the button goes down, the player taps it again and again and parries everything without ever timing anything.
Fix: Tell your AI: after letting go, make the guard wait a short while before it can go up again, and open the parry window only when the guard goes up.
Guarding hits from behind
The guard stops a hit that came from behind the character, so turning around is never a risk and the guard has no direction.
Fix: Tell your AI: only count a hit as guarded when it comes from the side the character faces. Other hits go through in full and cost no meter.
A hit the meter cannot pay for
A big hit lands on a nearly empty meter. The game either blocks it for free and the meter goes below zero, or it takes only the part the meter could not pay, and the guard never really breaks.
Fix: Tell your AI: if the meter is smaller than the hit, let the whole hit through, empty the meter and break the guard. Never let the meter go below zero.
A press and a hit in the same moment
The hit and the press arrive in the same tick. If the game raises the guard first, the player is saved by a press that came too late to count.
Fix: Tell your AI: decide the tick from how it began. A hit that arrives while the guard is not up is a full hit, even if the press is in the same tick.
Holding the button through a break
The player keeps holding the button while the guard is broken. The moment the break is over the guard goes straight up again, with a parry window the player never asked for.
Fix: Tell your AI: after a break, wait for the button to be let go once before a new guard can start.
How to check it works
- Your guard is up and the meter is full. A hit of 20 comes from the front: Only 4 gets through and the meter drops by 20.
- Your guard is up. A hit of 20 comes from behind: All 20 gets through and the meter does not change.
- You have just raised the guard. A hit of 40 comes from the front: No damage gets through, the meter does not change and one parry is counted.
- The guard has been up for longer than the parry window. A hit comes from the front: It is blocked as normal, not parried.
- The guard is down. A hit arrives in the same moment as the button press: The hit does its full damage and the guard goes up afterwards.
- Your guard is up with only 10 in the meter. A hit of 20 comes from the front: All 20 gets through, the meter is empty and the guard breaks.
- Your guard is up with exactly 20 in the meter. A hit of 20 comes from the front: It is blocked, the meter is empty and the guard holds until the next hit.
- Your guard has just broken. Another hit comes: It does full damage and the guard is not counted as broken a second time.
- The button is held down all through a break. The break ends: The guard stays down until the button is let go and pressed again.
- You let go of the guard. You press again straight away: The guard only goes up once the short wait is over.
- The meter is low and the guard is down. A second passes, and then many more: The meter rises by the refill speed and stops at full.
- Your guard is up. A hit of zero, below zero or no number at all comes: No damage gets through and the meter does not change.
Works well with
- Health and Damage: The guard only decides how much of a hit gets through. Health decides what that does, including the short protection after a hit. Run the guard first, then pass what it lets through to the health.
- Stamina System: Some games pay for blocks from the stamina bar instead of a separate guard meter. That is one bar fewer to read, but running about and guarding then compete for the same points.
- Dodge Roll: Guarding and rolling are two answers to the same attack. Give them different costs, so the player has a real reason to pick one. Let a roll cancel a guard that is up, but not a broken one.
Clashes with Jump Buffering: A remembered press from earlier could raise the guard the instant the wait is over, and open a parry window the player did not time. Do not remember guard presses. The player holds the button, and the guard goes up when the wait is over.
Common questions
what do i tell my ai to add blocking with a parry
Paste this: Add a guard: while the button is held, hits from the front are cut by four fifths and paid for from a guard meter. In the first fifth of a second after raising it, a front hit costs nothing. If the meter is too low for a hit, the hit goes through in full and the guard breaks. After letting go, make the guard wait a moment before it can go up again.
how long should a parry window be
Start with about a seventh of a second. That is a little under ten frames at sixty a second, which a player can learn without it feeling like luck. If players never manage it, widen it a little. If everyone parries everything, shrink it.
why can the player parry everything by tapping the button
Because the parry window opens every time the button goes down. Make the guard wait a short moment after letting go, so the window cannot open again straight away.
what happens when a hit is bigger than the guard meter
The whole hit goes through, the meter empties and the guard breaks for a while. Do not block part of it. A half-broken guard is hard to read and feels unfair.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 23 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