Stamina System
A stamina system is a bar that actions use up and rest fills back. Sprinting drains it steadily, a dodge costs a set amount or does not happen, and refilling starts after a short wait. Empty the bar and the character cannot sprint or dodge until it refills to a set level.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Stamina System" to my game.
What it should do: Stamina makes every action cost something right now, so the player paces themselves and each sprint or dodge becomes a real choice.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> full
full: Bar full
spend: Spending
wait: Short wait
refill: Refilling
worn: Worn out
full --> spend: sprint or big move
spend --> spend: keeps spending
spend --> wait: stops spending
spend --> worn: bar is empty
wait --> spend: spends again
wait --> refill: wait is over
refill --> spend: spends again
refill --> full: bar is full
worn --> worn: spending refused
worn --> refill: recovery level reached
```
Use these starting values:
- maxStamina: 100 units
- regenRate: 30 units/s
- regenDelay: 0.7 s
- sprintCost: 18 units/s
- recoverAt: 25 units
Watch out for these common mistakes:
- The bar looks right but the move still happens: Tell your AI: check the cost before spending, and refuse the move if the bar cannot pay for it. Then the bar cannot go too low in the first place.
- A bonus overfills the bar: Tell your AI: only spend stamina when the cost is above zero.
- The bar flickers at empty: Tell your AI: block all stamina use at zero until the bar reaches the recovery level.
- The bar refills between actions: Tell your AI: after each use, hold the refill for the short wait.
- Worn out for good: Tell your AI: a full bar always ends the worn-out period, and the refill speed is never zero.
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
Stamina makes every action cost something right now, so the player paces themselves and each sprint or dodge becomes a real choice.
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
- Bar full → Spending: sprint or big move
- Spending → Spending: keeps spending
- Spending → Short wait: stops spending
- Spending → Worn out: bar is empty
- Short wait → Spending: spends again
- Short wait → Refilling: wait is over
- Refilling → Spending: spends again
- Refilling → Bar full: bar is full
- Worn out → Worn out: spending refused
- Worn out → Refilling: recovery level reached
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| maxStamina | 100 units | How big the full bar is. A bigger bar lets the player keep going for longer. |
| regenRate | 30 units/s | How fast the bar fills back up, so how long the player has to pause. It is never zero, because a bar that cannot refill would leave the character worn out for good. |
| regenDelay | 0.7 s | How long the player must wait after using stamina before the bar starts to fill. Without this wait, the bar fills up between small actions. |
| sprintCost | 18 units/s | How fast sprinting drains the bar. |
| recoverAt | 25 units | How full the bar must get before the character can use stamina again. A higher level makes running out hurt more. A full bar always counts as recovered, even if this is set higher. |
What usually goes wrong
The bar looks right but the move still happens
The bar looks fine, yet a dodge the player could not afford still happened. The bar was only cut back into range afterwards.
Fix: Tell your AI: check the cost before spending, and refuse the move if the bar cannot pay for it. Then the bar cannot go too low in the first place.
A bonus overfills the bar
A bonus or a mistake gives an action a cost below zero, and the bar fills past its maximum.
Fix: Tell your AI: only spend stamina when the cost is above zero.
The bar flickers at empty
With no worn-out period, the player can keep tapping sprint at empty. The bar gains and loses a sliver again and again, and it flickers.
Fix: Tell your AI: block all stamina use at zero until the bar reaches the recovery level.
The bar refills between actions
If the bar refills in every moment the player is not spending, fast repeated actions cost almost nothing.
Fix: Tell your AI: after each use, hold the refill for the short wait.
Worn out for good
The recovery level is set higher than the full bar, or the bar never refills. The character stays worn out for good, and the game seems to hang.
Fix: Tell your AI: a full bar always ends the worn-out period, and the refill speed is never zero.
How to check it works
- Your stamina bar is full. you do a big move that costs 30: the bar drops by 30 and the game counts 30 as spent.
- Your bar holds less than a big move costs. you try the move: no stamina is spent and the move does not happen.
- Your bar is nearly empty. you keep sprinting: the bar stops at exactly zero and the character is worn out.
- The character is worn out but some stamina is left. you try a big move or a sprint: no stamina is spent.
- The character is worn out and resting. the bar fills back up: the character stays worn out until the bar reaches the recovery level, and not a moment longer.
- You have just used stamina. you stop and rest during the short wait: the bar stays put and only rises after the wait.
- Your bar is close to full. you rest and it fills up: it stops at exactly full.
- A big move with a cost of zero or below. you ask your AI to show you what happens when it is used: the bar does not change.
- The recovery level is set higher than the full bar. The bar runs empty and then refills all the way: The character can use stamina again.
Common questions
how do stamina systems work in games
Actions use up a bar and rest fills it back. Most games add a short wait before it refills, and a lockout when it runs empty, so running out really costs you.
how fast should stamina regenerate
Start with a full refill in three to four seconds of rest, after a wait of about 0.7 seconds. Slower makes every action feel heavier, faster makes the bar a formality.
what do i tell my ai to add a stamina bar
Paste this: Add a stamina bar. Sprinting can drain whatever is left, a dodge costs a set amount or does not happen, the bar starts refilling after a wait of about 0.7 seconds, and at empty the character cannot spend stamina until the bar has partly refilled.
why add a delay before stamina regenerates
Without it, the bar refills between quick actions, so a player who taps pays less than one who holds. The wait makes both pay the same.
Where it comes from
Earliest example we could find: Chainmail, 2nd edition (Gary Gygax and Jeff Perren, Guidon Games) (1972). Miniatures rules in which sustained marching, charging or melee makes troops fatigued, so that they attack and defend at a lower value until a pause restores them. This is exertion tracked for a unit as a rule state, not a meter on a character. The 2nd edition text was read directly; the 1971 first edition was not seen.
- 1972 Chainmail, 2nd edition (Gary Gygax and Jeff Perren, Guidon Games): Miniatures rules in which sustained marching, charging or melee makes troops fatigued, so that they attack and defend at a lower value until a pause restores them. This is exertion tracked for a unit as a rule state, not a meter on a character. The 2nd edition text was read directly; the 1971 first edition was not seen. [Chainmail: rules for medieval miniatures, 2nd edition (1972), Internet Archive full text][Chainmail (game), Wikipedia]
- 1984 Punch-Out!! (Nintendo, arcade): Boxing game with on-screen power meters that represent each fighter's stamina. The player's meter refills on successful strikes, and an empty meter means a knockout. This is the earliest visible stamina meter documented here. Sourced from Wikipedia only, which cites Computer and Video Games, August 1984; that review was not opened. [Punch-Out!! (1984 video game), Wikipedia][Health (game terminology), Wikipedia]
- 1987 Dungeon Master (FTL Games): Real-time CRPG in which fighting and running drain a character's stamina, and carrying a heavy load drains it faster. Low stamina reduces combat effectiveness and slows the character. Here stamina is a resource separate from health and tied to weight, which later games keep. [Dungeon Master, Part 2: The Playing of (Jimmy Maher, The Digital Antiquarian, 2015)][Dungeon Master, Part 1: The Making of (Jimmy Maher, The Digital Antiquarian, 2015)]
- 2000 Diablo II (Blizzard North): A stamina bar limits running. Its director David Brevik said in 2025 that he dislikes it: per PC Gamer, its purpose was to stop players fleeing or sprinting past combat. It is a useful case of a designer judging his own stamina system a mistake. The WebFetch tool saw only the article's headline, so the evidence quote is that headline; the body was read through a plain HTTP request. ['It makes me cringe every time': 25 years after Diablo 2 reshaped the RPG landscape, Diablo creator David Brevik still thinks its stamina bar sucks (Lincoln Carpenter, PC Gamer, 2025)][Branching out: How limiting skill choices made Diablo 2 more fun (GamesBeat, 2018; excerpt from Stay Awhile and Listen: Book II)]
- 2009 Demon's Souls (FromSoftware): Most actions spend from a stamina meter, so managing it is central to combat and not a limit on running alone. Sourced from Wikipedia only; no developer statement on this design was found. [Demon's Souls, Wikipedia]
- 2017 The Legend of Zelda: Breath of the Wild (Nintendo): Stamina is used as the limit on open-world movement in place of walls: Link can climb nearly anything, for as long as stamina lasts. Game Developer's coverage of the GDC talk presents this as a replacement for artificial barriers. [Key lessons developers can take away from Breath of the Wild (Bryant Francis, Game Developer, 2017)][The Legend of Zelda: Breath of the Wild, Wikipedia]
What was checked
- 14 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