Dungeon Generator



Programming Language: C#

Engine: Unity

Project Type: Personal Project.


Technical Features

Separating Axis Theorem Based Room Placement

The dungeon rooms are initially placed by randomly spawning them inside a radius. This results in a lot of overlapping squares. Separating Axis Theorem is then used to detect which squares are overlapping. the squares are then moved outward from the overlapped squares until they are no longer overlapping, similarity to how a lot of physics based collision system work. So Separating Axis Theorem is in this cause quite literally used to separate the dungeon rooms.

Delaunay Triangulation

Now that the rooms have been placed they need to be connected. the best way to connect a large volume of points is triangulation. Delaunay triangulation is a form of triangulation the results in the points being triangulated in such a way that no point is inside a triangle. this is idea for dungeons as that mean we wont have any crazy overlapping or strange long connections.

Urquhart Graph

Once the rooms have all been connected we don’t need every single connection so you want to construct a planer graph for a more balanced amount of connections. there are lots of different planar graphs that can be used but i chose the Urquhart graph due its simplicity and elegance.  how it works is you go through all the triangles and simply remove the longest side. this results in a very pleasing and effective set of coordinates.


In this project i created a procedural dungeon generator by combining several different algorithms. You start by randomly placing a set amount of rectangles in a defined radius. You then separate out the rectangles so none are overlapping using Separating Axis Theorem. once you have all the rooms placed you connect them up using Delaunnay Triangulation. This results in a nice set of triangles but we don’t need that many connections, we need to make a more dungeon layout which i do here by using a Urquhart graph to get a very dungeon-y lay out of paths. We now have all the data wee need we just have to construct it so we take all the rooms and replace the inner are with floor tiles and the outer areas with wall tiles, we then can replace connection lines with corridor tiles and then finally we have a dungeon.

This system will hopefully be fleshed out further in the future with the addition of a random interior to the dungeon rooms with multiple kinds of tiles.