Spielerando

Health and Damage

Health is a number that hits take away and healing gives back, between zero and a top. Armor trims each hit but never to nothing, and a short protection time after a hit stops one blow from landing many times. At zero the character is down until it is revived.

Also called: Hit points, Health bar, Life meter, Damage system.

A small felt hedgehog knight flinches as a giant acorn mace dents its shield, with five embroidered hearts above it, two just emptied, and a silver halo around it.
Thimblewick Knights, an invented felt-and-thread 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 "Health and Damage" to my game.

What it should do: Health tells the player how much more they can take. It turns every enemy and hazard into a price and gives healing a value.

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

```mermaid
stateDiagram-v2
  [*] --> healthy
  healthy: Open to hits
  protected: Protected
  down: Down
  healthy --> healthy: nothing lands
  healthy --> protected: a hit lands
  healthy --> down: the hit is deadly
  protected --> protected: protection goes on
  protected --> healthy: protection ends
  down --> down: stays down
  down --> protected: revived, protected
  down --> healthy: revived, no protection
```

Use these starting values:
- maxHealth: 100 units
- protectionTime: 0.8 s
- armor: 2 units
- minDamage: 1 units
- reviveHealth: 50 units

Watch out for these common mistakes:
- Overkill counts as damage dealt: Tell your AI: report what was actually taken off, never more than the health that was left.
- Armor flips a small hit into healing: Tell your AI: after armor, a hit does at least the minimum, and a hit of zero or less does nothing.
- A hit and a potion in the same moment: Tell your AI: the hit counts first, then the healing, and a character that is down cannot be healed. Pick one order and keep it.
- A sliver of health reads as zero: Tell your AI: show health rounded up, so anyone still alive shows at least 1, and decide being down by the real number.
- Hits right after getting back up: Tell your AI: start the protection time on a revive, just like after a hit.
- Strange numbers in a hit: Tell your AI: count a hit or a healing only when it is a real number above zero. Everything else does nothing.

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

Health tells the player how much more they can take. It turns every enemy and hazard into a price and gives healing a value.

How it runs, as a diagram

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

nothing landsa hit landsthe hit is deadlyprotection goes onprotection endsstays downrevived, protectedrevived, no protectionOpen to hitsProtectedDown
How it runs, as a diagram
  • Open to hits → Open to hits: nothing lands
  • Open to hits → Protected: a hit lands
  • Open to hits → Down: the hit is deadly
  • Protected → Protected: protection goes on
  • Protected → Open to hits: protection ends
  • Down → Down: stays down
  • Down → Protected: revived, protected
  • Down → Open to hits: revived, no protection

Good starting values

ValueStart withWhat it changes
maxHealth100 unitsHow big the full bar is. 100 leaves room to make hits 1 percent or 10 percent of it without fractions.
protectionTime0.8 sHow long after a landed hit more hits are ignored. Long enough to see what happened and step away, short enough that the player still feels danger. Zero turns it off.
armor2 unitsWhat is taken off every hit, flat. Small armor matters against small hits and fades against big ones.
minDamage1 unitsThe least a real hit does after armor. Above zero, armor can never make a character untouchable. Zero lets strong armor soak up a hit completely.
reviveHealth50 unitsHow much health a revive gives back. Half a bar gives a second chance without wiping out the cost of going down. It is cut to the full bar if that is smaller.

What usually goes wrong

Overkill counts as damage dealt

A hit of 900 on a character with 3 health left is reported as 900 damage. Score, life steal or a damage number on screen then shows far more than the hit really did.

Fix: Tell your AI: report what was actually taken off, never more than the health that was left.

Armor flips a small hit into healing

A hit of 1 against armor 2 comes out as minus 1, and the character gains health from being hit.

Fix: Tell your AI: after armor, a hit does at least the minimum, and a hit of zero or less does nothing.

A hit and a potion in the same moment

At 20 health, a hit of 30 and a potion of 30 arrive together. If the potion counts first, the character lives. If the hit counts first, it dies. Without a rule, the result changes between runs.

Fix: Tell your AI: the hit counts first, then the healing, and a character that is down cannot be healed. Pick one order and keep it.

A sliver of health reads as zero

After many small hits, 0.0004 health is left. The bar rounds down to 0, yet the character is alive and the player is confused.

Fix: Tell your AI: show health rounded up, so anyone still alive shows at least 1, and decide being down by the real number.

Hits right after getting back up

A character revived next to the enemy that dropped it is hit again in the same breath, and goes down in a loop.

Fix: Tell your AI: start the protection time on a revive, just like after a hit.

Strange numbers in a hit

A broken formula hands over not-a-number, or an endless value. One such number poisons the health for the rest of the game, and the bar shows nothing.

Fix: Tell your AI: count a hit or a healing only when it is a real number above zero. Everything else does nothing.

How to check it works

Works well with

Common questions

how do health points work in games

A number between zero and a top. Hits take it down, healing brings it back up, and at zero the character is down. Good versions add armor, a short protection time after a hit and a rule for who counts first.

how long should invincibility after a hit last

Start with about 0.8 seconds. Shorter and a single touch can hit many times in a row, longer and the player stops feeling danger.

how does armor reduce damage

A flat amount comes off each hit, with a minimum so that small hits still do something. Flat armor is strong against many small hits and weak against one big hit.

what do i tell my ai to add health

Paste this: Add health from 0 to 100. A hit takes off its damage minus armor 2, but at least 1. After a hit, ignore hits for 0.8 seconds. Healing stops at full. At zero the character is down until revived, and a hit counts before healing.

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