Weather System
A weather system keeps the sky one way for a while and then eases into a neighbouring kind: clear, cloudy, rain, storm. A change never jumps from clear to storm, and it fades in rather than switching. Chance decides what comes next, but it comes in as plain numbers, so the same numbers give the same sky.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Weather System" to my game.
What it should do: Weather gives a world a mood and a rhythm. It changes how the world looks and sounds, and it can change play: rain slows a fire, a storm closes a pass, a clear sky is a good time to travel.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> clear
clear: Clear sky
cloudy: Clouds
rain: Rain
storm: Storm
clear --> clear: sky stays clear
clear --> cloudy: clouds roll in
cloudy --> cloudy: clouds stay
cloudy --> clear: clouds break up
cloudy --> rain: rain starts
rain --> rain: rain goes on
rain --> cloudy: rain eases
rain --> storm: storm builds
storm --> storm: storm rages on
storm --> rain: storm passes
```
Use these starting values:
- meanDuration: 180 s
- fadeTime: 20 s
- wetBias: 0.4
Watch out for these common mistakes:
- Clear sky to storm in one step: Tell your AI: only let the weather change to a neighbour in a row from clear to cloudy to rain to storm, and make a storm pass through rain on its way out.
- The sky snaps: Tell your AI: keep the old weather and blend from it to the new one over a fade time. Show both in proportion.
- A change starts in the middle of a fade: Tell your AI: never plan a spell shorter than the fade time.
- Fast-forwarding runs a whole week of weather: Tell your AI: allow one change per step at most, and start the new spell from zero. After a skip, the sky is simply a new one.
- The weather cannot be replayed: Tell your AI: pass the two random numbers in from outside, from a generator used only for weather, and save the state of the sky with the game.
- A roll lands on the weather already there: Tell your AI: a change always goes to a different kind. If you want longer spells of one kind, raise the average length instead.
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
Weather gives a world a mood and a rhythm. It changes how the world looks and sounds, and it can change play: rain slows a fire, a storm closes a pass, a clear sky is a good time to travel.
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
- Clear sky → Clear sky: sky stays clear
- Clear sky → Clouds: clouds roll in
- Clouds → Clouds: clouds stay
- Clouds → Clear sky: clouds break up
- Clouds → Rain: rain starts
- Rain → Rain: rain goes on
- Rain → Clouds: rain eases
- Rain → Storm: storm builds
- Storm → Storm: storm rages on
- Storm → Rain: storm passes
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| meanDuration | 180 s | How long a spell of weather lasts on average. Each spell lasts between half and one and a half times this. Three minutes is long enough to settle in and short enough to see change in one visit. |
| fadeTime | 20 s | How long a change takes to blend in. Too short and the sky seems to switch, too long and the weather is always half one thing and half another. A spell is never shorter than this. |
| wetBias | 0.4 | How rainy the world is. It is the chance that clouds lead to rain, and half that for rain to lead on to a storm. At 0 the sky never rains. |
What usually goes wrong
Clear sky to storm in one step
The next weather is picked from all kinds at random. A bright day turns into a storm with no warning, and a storm ends straight into sunshine.
Fix: Tell your AI: only let the weather change to a neighbour in a row from clear to cloudy to rain to storm, and make a storm pass through rain on its way out.
The sky snaps
The weather switches the moment the spell ends. Rain starts at full strength in one frame, the light jumps, and the player sees a cut.
Fix: Tell your AI: keep the old weather and blend from it to the new one over a fade time. Show both in proportion.
A change starts in the middle of a fade
A spell is shorter than the fade. The next change begins before the last one has finished, and the old blend is thrown away, so the sky jumps.
Fix: Tell your AI: never plan a spell shorter than the fade time.
Fast-forwarding runs a whole week of weather
The player sleeps for eight hours or the game is paused for ages. The code loops through every spell it missed, or does a thousand changes in one step.
Fix: Tell your AI: allow one change per step at most, and start the new spell from zero. After a skip, the sky is simply a new one.
The weather cannot be replayed
The weather asks the game's random generator directly, and other things use it too. Two players, or a test, get a different sky from the same start, and a saved game gives a different weather after loading.
Fix: Tell your AI: pass the two random numbers in from outside, from a generator used only for weather, and save the state of the sky with the game.
A roll lands on the weather already there
The next weather is picked from all kinds including the current one. Sometimes nothing changes, spells silently double in length, and a short test of the mechanic seems broken.
Fix: Tell your AI: a change always goes to a different kind. If you want longer spells of one kind, raise the average length instead.
How to check it works
- A new game. the weather system starts: the sky is clear, with nothing fading in or out.
- A clear sky with a spell that has a set number of seconds left. that time runs out, second by second: the sky stays clear until the very last second and then turns cloudy, and the new spell starts from zero.
- An average spell length of 180 seconds. the random number for the length is 0, 0.5 and nearly 1: the spell lasts 90 seconds, 180 seconds and nearly 270 seconds.
- Any weather and any random number. the weather changes: clear always turns cloudy, a storm always turns to rain, and clouds and rain only go to their own neighbours.
- A rain bias of 0, then 1, then the starting 0.4. clouds change, for different random numbers: at 0 they never lead to rain, at 1 they always do, and at 0.4 they lead to rain for numbers below 0.4 only, and rain leads on to a storm for numbers below 0.2.
- A sky that has just changed from clear to cloudy. the fade time passes, half at a time: the sky shows all clear at first, an equal mix after half the time and all cloudy at the end.
- An average length of 30 seconds and a fade time of 120 seconds. a new spell is planned: it is planned for 120 seconds, and the weather does not change again before the fade has run its course.
- A clear sky. a hundred thousand seconds pass in a single step: the weather changes exactly once and the new spell starts from zero.
- The same starting values and the same list of random numbers. the weather runs through thousands of steps, twice: both runs give exactly the same sequence of weather.
Works well with
- Day-Night Cycle: Both change the light. If each sets it on its own, they fight, so let the weather scale what the cycle gives. Run the day and night cycle first and the weather second, and let the weather dim the light the cycle gives.
- Hunger and Thirst: Hot clear weather can drain thirst faster and rain can refill it. Let the weather expose a number the other mechanic reads, and keep the weather unaware of survival.
- Status Effects: A storm that sets cold but never clears it leaves the player cold for good after the sun is back. Let the weather place a status on the player and take it off when the weather moves on, not the other way round.
- World State Flags: Without that a reload starts a new clear sky in the middle of a storm. Save the kind, the previous kind, the age and the length of the spell with the game, and load them before the first step.
Common questions
how does a weather system work in games
The game keeps one kind of weather for a spell, then picks a neighbouring kind at random and blends into it over some seconds. Chance only decides which neighbour, so a storm does not appear out of a clear sky.
how long should weather last in a game
Start with about three minutes on average, with each spell between half and one and a half times that. Shorter feels restless, longer means many players never see most of the weather.
how do i make weather the same for every player
Do not use the game's general random numbers. Feed the weather its own numbers from a shared starting value. The same start and the same numbers then give the same sky on every machine, and in every test.
what do i tell my ai to add a weather system
Paste this: Add weather in a row from clear to cloudy to rain to storm. It changes only to a neighbour, after a spell of about three minutes, and fades in over 20 seconds. The random numbers come in from outside, so the same numbers give the same sky.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 12 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