Cover System
Cover lets a character stop attacks from one side by standing behind an object. The cover takes the damage first and passes on only what is left when it breaks. Stepping in and peeking to shoot leave the character open, and attacks from the other side ignore the cover completely.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Cover System" to my game.
What it should do: Cover turns a fight into a choice between safety and shooting: the player hides to survive, then pays with exposure each time they peek to hit back.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> open
open: In the open
entering: Stepping in
covered: Behind cover
peeking: Peeking
open --> entering: cover button held
entering --> covered: step is done
entering --> open: button let go
covered --> peeking: peek pressed
covered --> open: leaves or cover breaks
peeking --> covered: peek is over
peeking --> open: leaves cover
```
Use these starting values:
- maxHealth: 100
- coverHealth: 60
- enterTime: 0.3 s
- peekTime: 0.45 s
Watch out for these common mistakes:
- Hits from the other side: Tell your AI: cover has a side. Only a hit from that side goes into the cover, and a hit from the other side hurts the character in full.
- Damage bigger than the cover: Tell your AI: the cover takes what it has left, and only the rest goes through to the character.
- A hit and a peek in the same moment: Tell your AI: decide from where the character stood when the tick began. The hit goes into the cover, and the peek starts afterwards.
- Peeking for no cost: Tell your AI: a peek lasts a set minimum time, even if the button is let go at once.
- Cover that was destroyed while in use: Tell your AI: when the cover's health reaches zero, put the character back in the open that same tick and refuse to step into that cover again.
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
Cover turns a fight into a choice between safety and shooting: the player hides to survive, then pays with exposure each time they peek to hit back.
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
- In the open → Stepping in: cover button held
- Stepping in → Behind cover: step is done
- Stepping in → In the open: button let go
- Behind cover → Peeking: peek pressed
- Behind cover → In the open: leaves or cover breaks
- Peeking → Behind cover: peek is over
- Peeking → In the open: leaves cover
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| maxHealth | 100 | The character's full health. Cover is worth more the sooner a few hits would end the fight. |
| coverHealth | 60 | What a new piece of cover takes before it breaks. About half the character's health means cover buys time but cannot be sat behind forever. |
| enterTime | 0.3 s | Time to step in behind cover, with no protection yet. Long enough to be a real choice, short enough not to feel sticky. |
| peekTime | 0.45 s | The least time a peek lasts once it has begun. Letting go early does not shorten it, so a quick peek is never free. |
What usually goes wrong
Hits from the other side
If cover protects from every direction, an enemy that walks around it changes nothing, and the player can sit behind one crate all fight.
Fix: Tell your AI: cover has a side. Only a hit from that side goes into the cover, and a hit from the other side hurts the character in full.
Damage bigger than the cover
A big hit on nearly broken cover can either vanish completely or hurt the character for the whole amount, so the same hit feels very different from one moment to the next.
Fix: Tell your AI: the cover takes what it has left, and only the rest goes through to the character.
A hit and a peek in the same moment
If the game moves the character out first and then checks the hit, a player who pressed peek a split second before the hit gets hurt for a shot that came in while still hidden.
Fix: Tell your AI: decide from where the character stood when the tick began. The hit goes into the cover, and the peek starts afterwards.
Peeking for no cost
If a quick tap of peek lets the player shoot and be back behind cover in one frame, the exposure is too short to ever matter and the enemy can never punish it.
Fix: Tell your AI: a peek lasts a set minimum time, even if the button is let go at once.
Cover that was destroyed while in use
When the cover breaks, a character still marked as hidden stays safe behind nothing, or the game lets the player step back into a piece that no longer exists.
Fix: Tell your AI: when the cover's health reaches zero, put the character back in the open that same tick and refuse to step into that cover again.
How to check it works
- Your character stands behind cover with 100 health and the cover has 60. An attack of 20 comes from the side the cover shields: The character still has 100 health and the cover has 40.
- Your character stands behind cover with 100 health and the cover has 60. An attack of 20 comes from the other side: The character has 80 health and the cover still has 60.
- Your character has just started to step in behind cover. An attack of 25 comes before the step is done: The character takes all 25 and the cover takes none. The step takes about 0.3 seconds.
- Your character peeks from behind cover. An attack of 30 comes from the shielded side: The character takes all 30 and the cover takes none.
- Your cover has only 10 left. An attack of 25 comes from the shielded side: The cover drops to zero, the character loses 15 and is back in the open.
- Your cover has just broken. The player keeps holding the cover button: The character stays in the open.
- Your character stands fully behind cover. Press fire: Nothing is fired. Peeking or standing in the open does fire.
- Your character starts to peek and the player lets go at once. Wait: The character stays out for about 0.45 seconds before going back behind cover.
- Your character is fully behind cover. A hit from the shielded side and the peek button come in the same tick: The cover takes the hit and the character starts peeking afterwards.
- Your character is behind cover or stepping in. The player lets go of the cover button, or the cover is no longer within reach: The character is in the open.
- Your character has 100 health. An attack of 500 comes: Health is zero, not below.
- Your character stands behind cover. An attack with damage below zero comes: Neither the character nor the cover gains anything.
Works well with
- Health and Damage: The cover is a layer in front of health. Keep the damage rules in one place so cover and open ground share them. Run the hit through the cover first, then give the rest to the health.
- Knockback: A shove can push a character out from behind cover. Decide whether a hit that the cover took still shoves.
Clashes with Dodge Roll: A roll that is safe from every hit makes cover less needed, and a roll out of cover can end inside the line of fire. Let a roll start from cover, and treat the character as in the open from the first moment of it.
Common questions
what do i tell my ai to add a cover system
Paste this: Add a cover system. Cover shields one side and has health of its own. A hit from that side goes into the cover first and only the rest hurts the character. Stepping in takes 0.3 seconds with no protection, peeking to shoot lasts at least 0.45 seconds and is open, and hits from the other side ignore the cover.
how much health should cover have
About half the character's health is a good start. Cover that can take more makes fights slow, and cover that breaks in one hit is not worth walking to.
can the player shoot from behind cover
Here the player has to peek to fire. That is the price of safety. If your game allows blind fire from cover, make it weaker so peeking still has a reason.
why do enemies at the side ignore cover
Cover only stops what comes from the side it faces. That is what gives enemies a way to force the player out, by moving around instead of shooting harder.
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