# Help Connecting Procedurally Generated Rooms

I’m working on a project where there’s a map of ‘tiles’ and rooms are procedurally generated by selecting a random tile in the folder (starting wall), then raycasting in either in +x, -x, +z, or -z directions. If the wall the ray hits is too far from a given ‘MaxDistance’ variable we reset back to the randomly selected ‘StartingWall’ and when we find a wall we put it inside the table of ‘RoomWalls’ after first making sure the wall isn’t already in the table to not have repeats walls. I also delete one room at a time and make sure they aren’t overlapping by restarting the process completely if the raycast hits ‘nothing’ because that would have to mean it hit an already carved out room or the edge of the map. So here’s an image showing what I’ve got going on so far:

So as you can see we have 7 procedurally made rooms that do not overlap and have somewhat random ‘sizes’ the size variable is the given number of walls I want the room to carve out.

Now I want to make little 1 thick paths that connect the rooms. One idea I had was to store the walls in the rooms positions with the highest and lowest x and z positions so I would know where the ‘edges’ of the rooms are and the connecting the closest edges to each other or something along those lines. I’m kind of all ears here and looking for possibly all around better solutions. I don’t want the paths cutting through rooms that are between and it would be nice to add some element of randomness, but maybe I should just start in the middle and create a web? Any ideas/solutions here much appreciated.

1 Like

I just realized this is what you just said, oops.

You could probably list out what extremes for the boundaries (edge) per each region is, then find the closest region of that edge and connect the two, unless already connected.

Listing Extremes (edges based on maximum deviation from center of region)

Then bridge them together with their opposite edge.

(Or just get the closest edge between the two regions)

But I’ll pitch in another idea that goes along with what you previously said

Formulated other idea, based on wave function collapse. not sure how you’ll do this based on randomness, albeit the idea is to cut out these patters, save the topography of each region, and then assign the maximums as connecting points, and you can spawn each region like how you would with a maze.

1 Like

Thanks for the response I’m thinking connecting the ‘extremes’ as you put it is probably the the simplest effective solution and probably what I’ll end up trying to implement. So tell me how this sounds to you because it’s all still really complicated to me but maybe I’m overthinking it:

Store positions of the ‘extremes’ of each room as well as a way to know which room it belongs to.
Pick one room and connect it’s ‘extremes’ to other rooms with closest ‘extremes’ then repeat for the room(s) we just connected until all rooms are connected.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.