RTS and MOBA Fog
This guide sets up fog of war for a strategy game: many units revealing the map, enemy units hidden in the fog, and buildings that stay visible once discovered.
1. The fog
- Create an empty object at the center of the map and add Fog Of War. Keep Team 0 for the player.
- Click Fit Area To Scene, or set Size to the size of the map.
- Choose Memory:
- Remember explored: classic RTS fog. Unexplored areas are black, explored areas dimmed.
- Visible only (MOBA): the whole map is known, only what the team sees right now is clear. Set the Explored color to how dark the unseen map should be.
- Pick a look under Style. For a big map, Texture with drifting clouds reads well from far away.
The texture size is the area times Resolution. A 400 × 400 map at the default 4 pixels per unit needs 1600 × 1600 pixels. If the map is larger than the texture limit allows, lower Resolution: RTS fog does not need sharp edges, and Edge Softness hides the pixels.
2. Units: revealers or line of sight
Each unit that reveals the map gets a Vision Source with Team 0 and Field of View 360. Then decide per unit type:
| Unit | Blocked By | Why |
|---|---|---|
| Most units, buildings, wards | Nothing | A revealer: a plain circle, no physics queries, the cheapest source |
| Units where walls should matter, e.g. scouts in a city, units in a forest | Your wall layers | Exact line of sight, blocked by walls and trees |
Revealers and line-of-sight sources can be mixed freely in one fog.
For units that move slowly or far from the camera, set Update Every (s) to 0.1 to 0.2. The fog fades smoothly, so the lower update rate is hard to notice.
3. Enemies in the fog
- Give enemy units a Fog Hider with Shown To Team 0. They are hidden while none of the player's units sees them.
- On enemy buildings, also turn on Stay Visible Once Seen. The player keeps seeing a base after scouting it, like in most RTS games.
- For large buildings, add Visible Points at the corners, so the building shows up as soon as one corner is in view, not only its center.
If enemies have their own Vision Sources (team 1), the enemy AI can use them, for example with VisionSystem.IsVisibleToTeam(1, position), without any fog for team 1.
4. Reacting to the fog in code
using Renvix.VisionFog;
using Renvix.VisionFog.Presentation;
// Can the player's team see this point right now?
bool visible = VisionSystem.IsVisibleToTeam(0, position);
// Is this enemy visible? (same result the hider uses)
bool shown = enemy.GetComponent<FogHider>().IsVisible;
// New match: forget everything explored.
fog.ResetExplored();
// Map revealed by an item or a cheat.
fog.RevealAll();
Use IsVisibleToTeam to decide whether to show attack effects, sounds or minimap pings of enemies.
5. Several players
Every player's team needs its own Fog Of War with its own memory. Show only the fog of the local player's team and disable the others. For a hot seat game or a replay, enable the fog of the team whose turn it is, and set FogHider.ViewerTeam on the hiders to the same team. See Teams.