Generate Cellular Automata Cells
Generates organic cave-like regions using a cellular automata smoothing process.
Starts from random noise inside Bounds, then iteratively applies simple local rules to evolve walls and floors into natural shapes.
What it does
- Initializes a grid in Bounds where each cell starts as wall with probability Initial Wall Chance (otherwise floor).
-
Repeats Iterations times:
- Counts neighbors (4-way or 8-way) around each cell.
- Applies two thresholds:
- Wall Erode Threshold - walls with too few wall neighbors erode into floor.
- Wall Regrow Threshold - floors with many wall neighbors regrow into wall.
- Returns the final set of open/floor cells as Vector2Int positions.
This produces anything from blobby caverns to chunky, gridded tunnels depending on your neighbor mode and thresholds.
Inputs
| Field | Description |
|---|---|
| Bounds | BoundsInt area to simulate (cell/grid coordinates). |
| Initial Wall Chance | Probability each cell starts as wall. Lower → more open; higher → more solid. Typical range 0.45–0.65. |
| Use 8 Neighbors | When true, use 8-way neighbor counts (rounder, more organic). When false, use 4-way (chunkier, more orthogonal). |
| Wall Erode Threshold | Walls with fewer than this many wall neighbors erode to floor. Higher → walls erode more easily. |
| Wall Regrow Threshold | Floors with at least this many wall neighbors regrow to wall. Higher → open space stays open. |
| Iterations | Number of smoothing passes (1–6). Fewer = noisy; more = smoother (too many can collapse to all floor or all wall). |
Outputs
| Field | Description |
|---|---|
| Cells | All final floor cells as Vector2Int positions (optional). |
How it works (intuition)
- Think of Wall Erode Threshold as “how isolated can a wall be before it crumbles.”
- Think of Wall Regrow Threshold as “how surrounded must a floor be before it fills back in.”
- Using 8-way neighbors blends diagonals into decisions (rounded caverns).
Using 4-way limits influence to N/S/E/W (blockier patterns).
Tips & pitfalls
- Start with Initial Wall Chance ~0.55, Erode=4, Regrow=5, Iterations=5, 8 neighbors - then tweak.
- If caves are too open: increase Initial Wall Chance or Regrow Threshold, or add Iterations.
- If caves are too tight: decrease Initial Wall Chance or Regrow Threshold, or add Erode (raise it) and Iterations.
- Prefer 8 neighbors for natural caverns; 4 neighbors for retro/grid vibes.
- Chain with filters:
- FilterCellsKeepLargestRegions to ensure one contiguous cave.
- FilterCellsRemoveSmallRegions to clear specks.
- FilterCellsJoinAllRegions to connect pockets with corridors.
- FilterCellsBridgeDiagonals to fix corner-only contacts for 4-way pathing.
- For reproducible results, set a seed first with Random → Random Init State.