Spielerando

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.

Also called: Survival needs, Hunger system, Thirst meter, Food and water.

A tired llama traveller climbs a desert dune with a nearly empty water gourd, as a distant oasis glows ahead and two round gauges float beside it, the drop-shaped one almost empty.
Dunewick Drifters, an invented desert-crossing journey game. 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 "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.

time passesa need runs lowa need runs outstill loweats or drinksa need runs outstill starvingeats or drinkseats and drinks wellNeeds metRunning lowStarving
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

ValueStart withWhat it changes
maxNeed100 unitsThe full level of each need. The size mostly sets how precise eating can be, since the drain is set per second.
foodDrain0.08 units/sHow 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.
waterDrain0.15 units/sHow 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.
lowFraction0.2The 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.
starveDamage1 health/sThe 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

Works well with

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.

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