Hunger and Thirst
Hunger and thirst are two needs that drain with time and are refilled by eating and drinking. When one is empty, the character takes harm for every second it stays empty. The harm is counted by exact time, so a long sleep and many short moments cost the same.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Hunger and Thirst" to my game.
What it should do: Hunger and thirst give the world a clock and make food and water worth finding. They push the player to leave safe ground and plan the trip.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> fine
fine: Needs met
low: Running low
empty: Starving
fine --> fine: time passes
fine --> low: a need runs low
fine --> empty: a need runs out
low --> low: still low
low --> fine: eats or drinks
low --> empty: a need runs out
empty --> empty: still starving
empty --> low: eats or drinks
empty --> fine: eats and drinks well
```
Use these starting values:
- maxNeed: 100 units
- foodDrain: 0.08 units/s
- waterDrain: 0.15 units/s
- lowFraction: 0.2
- starveDamage: 1 health/s
Watch out for these common mistakes:
- Damage that depends on the frame rate: Tell your AI: multiply the damage by the time that passed, so it is per second.
- A long sleep skips the hunger: Tell your AI: work out how many seconds of the step a need was empty, and count harm only for those. Show the warning when waking up.
- Eating more than fits: Tell your AI: cap the level at full. If you want food to count more, make a bigger maximum on purpose.
- A need that goes below zero: Tell your AI: never let a level go below zero.
- Eating in the same moment as starving: Tell your AI: apply eating and drinking first, then the drain and the harm.
- Food that drains the need: Tell your AI: count eating and drinking only when it is a real number above zero. If poison should hurt, make it a separate effect.
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
Hunger and thirst give the world a clock and make food and water worth finding. They push the player to leave safe ground and plan the trip.
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
- Needs met → Needs met: time passes
- Needs met → Running low: a need runs low
- Needs met → Starving: a need runs out
- Running low → Running low: still low
- Running low → Needs met: eats or drinks
- Running low → Starving: a need runs out
- Starving → Starving: still starving
- Starving → Running low: eats or drinks
- Starving → Needs met: eats and drinks well
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| maxNeed | 100 units | The full level of each need. The size mostly sets how precise eating can be, since the drain is set per second. |
| foodDrain | 0.08 units/s | How fast hunger grows at normal effort. At 0.08 a full stomach lasts about 21 minutes, so a meal every session feels right. It is never zero, or hunger would never matter. |
| waterDrain | 0.15 units/s | How fast thirst grows at normal effort. At 0.15 water lasts about 11 minutes, so thirst comes first and sends the player toward a river before food becomes a worry. |
| lowFraction | 0.2 | The share of the full level at which a need counts as low. It is the moment to warn the player, while there is still time to act. |
| starveDamage | 1 health/s | The harm per second for each empty need. 1 a second takes 100 seconds to kill a full bar of 100, enough time to find something. Zero turns the harm off. |
What usually goes wrong
Damage that depends on the frame rate
A fixed 1 damage is dealt on every frame a need is empty. At 120 frames a second the character dies twice as fast as at 60, and a slow computer almost never dies.
Fix: Tell your AI: multiply the damage by the time that passed, so it is per second.
A long sleep skips the hunger
The player sleeps through the night, which the game skips in one long step. Either nothing drains, or the need hits zero and the character dies without a single second of warning.
Fix: Tell your AI: work out how many seconds of the step a need was empty, and count harm only for those. Show the warning when waking up.
Eating more than fits
A feast adds 80 to a stomach that is at 95. The level shows 175, and the player is safe from hunger for far longer than the design intended.
Fix: Tell your AI: cap the level at full. If you want food to count more, make a bigger maximum on purpose.
A need that goes below zero
After a long step the level reads minus 40. The bar draws backwards, and the first meal only brings it back to zero while the player is still starving.
Fix: Tell your AI: never let a level go below zero.
Eating in the same moment as starving
A need is at zero and the player eats in the very same moment. If the harm is counted first, the meal arrives too late and the character is hurt anyway.
Fix: Tell your AI: apply eating and drinking first, then the drain and the harm.
Food that drains the need
A bad recipe gives a food value of minus 20, or a formula returns not-a-number. The need drops, or turns into not-a-number and never recovers.
Fix: Tell your AI: count eating and drinking only when it is a real number above zero. If poison should hurt, make it a separate effect.
How to check it works
- Both needs are full at 100. 100 seconds go by at normal effort: food is 92, water is 85, and no harm was done.
- Both needs are full. time goes by and nothing is eaten or drunk: water runs low well before food does.
- Food is at 90 and water at 95. you eat 50 and drink 50: both stop at exactly 100.
- Food is at zero. one second goes by, and in another case half a second: the harm is 1, and in the other case 0.5.
- Food and water are both at zero. one second goes by: the harm is 2.
- Food is at 0.5, which lasts 6.25 seconds. 10 seconds go by in one step: the harm counts only the last 3.75 seconds.
- Food is at zero. you eat 10 in the moment a second goes by: no harm is done.
- Both needs are full. ten seconds go by at double effort, and in another case at zero effort: the loss is twice as big, and with zero effort nothing is lost.
- Food is at 20 and water at 10. 600 seconds pass once as one step and once as 600 steps of one second: the levels and the total harm are the same.
Works well with
- Health and Damage: Decide whether this harm goes through armor and protection time. Usually it should not, or protection time would hide it. Hand the damage from here to health and let health apply it.
- Inventory System: Items that spoil or weigh something give the needs a reason to keep moving. Let food and water be items, and call the eat and drink amounts from their use.
- Crafting System: Cooking that raises the value of food gives players something to do about hunger besides eating it raw. Crafting turns raw finds into meals and clean water, and this mechanic only counts the amount eaten.
Common questions
how do hunger and thirst work in survival games
Two levels slowly fall over time. Eating and drinking raise them. When one hits zero, the character takes harm every second until it is raised again.
how fast should hunger and thirst drain
Start with a full stomach lasting about 20 minutes and a full water supply about 10. Thirst should come first. Slower than that and the player forgets about it, faster and it feels like a chore.
should starvation kill the player instantly
No. Give a warning when a need runs low and let the harm build up per second, so the player has time to find something. Sudden deaths feel unfair.
what do i tell my ai to add hunger and thirst
Paste this: Add hunger and thirst, each from 0 to 100. Hunger falls 0.08 a second and thirst 0.15. Eating and drinking apply first and stop at 100. An empty need costs 1 health per second, counted by exact time, also across long skips.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 19 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