Dungeon generation
Rooms and corridors from a seed.
Hand-made levels run out. A dungeon generator splits the map (binary space partitioning) or carves with random walkers, places rooms, and connects them with corridors so every room is reachable. With a seed, every layout can be replayed and shared.
Try this: Explore the generated dungeon and find the key in the far room (orange on the minimap). Press G for a new one. Turn off the connectivity check and some dungeons leave the key cut off.
Every room is connected. Find the key in the far room.
Prompt bit
Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.
Generate dungeons from a seed: split the map with BSP into leaves, place one room per leaf with a margin, connect sibling rooms with L-shaped corridors so all are reachable, finish in under 0.05 s, and regenerate if fewer than 5 rooms fit.
Write a seeded dungeon generator (2D grid; the layout can drive 3D rooms too). Use a seeded RNG. BSP method: recursively split the map rectangle horizontally or vertically at a random position (keeping minimum leaf size, default 8x8) until leaves are small; place a room in each leaf with a random size and a 1-tile margin; walk back up the tree connecting the two children of each node with an L-shaped corridor between room centres, which guarantees connectivity. Walker method for caves: start in the middle and step randomly carving floor until a target fill (about 40%), then smooth with a cellular automaton pass. Afterwards: pick the start and exit as the farthest pair by BFS distance, place enemies and loot by distance, run autotiling, and reject and regenerate maps that are too small. Keep everything deterministic from the seed.
Where it's used
- Roguelikes and roguelites: new floors every run
- Dungeon crawlers: rooms, corridors and loot
- Survival games: caves and mines
- Action RPGs: randomized side dungeons
- Daily challenges: shared seeds
Common mistakes
Rooms that are unreachable, overlapping rooms, unseeded randomness so bugs cannot be reproduced, start and exit next to each other, and no checks so some maps are tiny.
Writing this with an AI assistant? See our best AI coding assistants for game developers.
Missing a concept? Request one.



