Weather
Add rain, snow, fog, and wind effects to your game world.
Introduction
Weather systems add atmosphere and gameplay variety. This guide covers rain, snow, fog, wind, and weather state transitions.
Guide 6 of 25
Screenshot
Step-by-Step Guide
Create a weather manager
Add an empty object named WeatherManager with a script to centralize weather state.
Add rain particles
Create a particle system for rain. Set emission rate (500-2000/sec), direction (wind-affected), and speed.
Add snow particles
For snow, use slower particles with sway. Lower emission rate (100-500/sec) and larger size.
Configure fog
Add exponential fog with adjustable density. Rain increases fog; snow uses brighter fog color.
Set wind
Configure global wind direction and strength. Wind affects particles, grass, trees, and cloth.
Transition weather states
Smoothly lerp between presets (clear, cloudy, rain, storm, snow) over 10-30 seconds.
FluxScript Example
Here is a complete FluxScript implementation for this guide:
state = "clear"
const PRESETS = {
clear: { fog: 0.01, rain: 0, wind: 0.2, light: 1.2 },
cloudy: { fog: 0.03, rain: 0, wind: 0.5, light: 0.8 },
rain: { fog: 0.06, rain: 800, wind: 1.0, light: 0.5 },
storm: { fog: 0.10, rain: 2000, wind: 2.5, light: 0.3 },
snow: { fog: 0.08, snow: 300, wind: 0.8, light: 0.6 }
}
func setWeather(newWeather) {
state = newWeather
p = PRESETS[newWeather]
scene.setFog(p.fog)
scene.find("RainSystem").setEmissionRate(p.rain || 0)
scene.find("RainSystem").setVisible(p.rain > 0)
world.setWind(p.wind)
scene.find("SunLight").setIntensity(p.light)
ui.toast("Weather: " + newWeather)
}
on timer("weatherCycle", 120) {
options = ["clear", "cloudy", "rain", "storm", "snow"]
setWeather(options[math.random(options.length)])
}Node Graph Example
Prefer visual programming? Here is the equivalent Node Graph:
[Function: setWeather] --> [Get Preset]
--> [Set Fog] --> [Set Rain emission + visibility]
--> [Set Wind] --> [Set Sun Intensity] --> [Toast]
[On Timer "weatherCycle" 120s] --> [Random: weather type]
--> [setWeather]Optimization Tips
Keep your implementation fast and efficient with these optimization tips:
- Use shaders for rain instead of particles on mobile. A screen-space rain shader is 5x cheaper than 800 particle drops.
- Pool weather particle systems. Do not create/destroy per weather change — toggle visibility and adjust emission rate.
- Limit fog density on mobile. Exponential fog is expensive in fragment shaders.
- Smoothly transition between weather states over 10-30 seconds. Instant changes feel jarring.
Common Mistakes
Too many rain particles on mobile
Limit to 300-500 drops. Use a rain shader instead of particles for better performance.
Weather changes too frequently
Weather cycles should be 2-5 minutes minimum. Rapid changes break immersion.
