How to make pathways/corridors in a randomly generated dungeon

Hi there,

I have been working on a 2D project where I am trying to make a randomly generated dungeon. So far, I have been able to spawn the rooms at different positions and connect them using a minimum spanning tree algorithm. You can see what I have so far in the attached image. But now I am stuck at what would be the last part and that is to connect the rooms through pathways or corridors. I would like the corridors to be straight or form an ‘L’ shape when connecting to rooms but I am having difficulty understanding how I should go about it all. So, if anyone can help me out then that would be great :slight_smile:

Well first I would find the MIN/ MAX of both rooms x and y and compare them. If they overlap (a minimum of the width of your corridor) then you don’t have to make a path with a bend(and the following works regardless of direction).


So assuming they do “overlap” in this case now we choose a random position on the overlap that is a random distance between Overlap MIN and Overlap Max - corridor width.
4405708--400972--Pos1.PNG

Of course this doesn’t take into account checks for existing rooms or hallways but that is a different question entirely. I’ll leave you to it to figure out how to do the L shaped corridors when there is no overlap.

Ok so I found the solution and it’s actually rather simple and elegant. Thanks to this article I was able to find out that the first step is to calculate the midpoint between 2 rooms. If the midpoint falls within the bounds of the rooms, then stretch a path across the midpoint to the bounds. Otherwise, make an ‘L’ shaped corridor from the center of one room to the center of the other.

Thanks to everyone who tried to help out. Take a look at the images below to see what different generations of the map looks like




I still recommend my solution to solve for hallway width. You only have a line for your hallways right now.

The line is drawn for visualization only. I am just doing a Debug.DrawLine to show them. In the actual game, I will replace the lines with sprites that have some width.