Remove excess wall from randomly generated hallway

I’ve recently been working on randomly generating hallways. I do this by generating the floors, and then adding 4 walls along the edges of the floor parts. The problem is that when the hallway turns, the walls block off the hallway, as seen here:

I have tried doing this by using unions that will negate out the parts of the wall that are in the way,
but this is a pretty hacky solution and also leads to weird collisions. Is there some way that I can do this with math instead? I imagine this means somehow determining where these unwanted wall sections are, and then resizing and moving the walls accordingly.

I'm not sure if putting the code here is neccesary, but here's the relevant bit

I understand that this code is pretty hard to read, but basically I’m just creating four walls around each of the edges of the floor part to create the hallways.

	-- generate walls
	local x, z = true,true
	for index, floor in pairs(Floors:GetChildren()) do
		for i = 1, 4 do
			local pt = floor:Clone()
			local mult = z and 1 or -1
			pt.Size = x and Vector3.new(1,height,floor.Size.Z) or Vector3.new(floor.Size.X,height,1)
			pt.Position = floor.Position+(x and Vector3.new(mult*floor.Size.X/2,height/2,0) or Vector3.new(0,height/2,mult*floor.Size.Z/2))
			pt.Parent = Walls
			local h = x; x = not z; z = h
		end
	end
	
	-- remove excess walls that block path?

I see a potential in the polybool libary to be used especially the union feature.

Since you are using only rectangular hallways you can replace them with a rectangular node then use the union feature to only connect the nodes highlighted by the library and not the ones that are blocking off the routes.

So I fixed this in a pretty hacky way that I’m not super proud of, but it works for the time being. Basically, if a wall is touching 2 floors, then I know that the wall is in the way. Then I just do a bit of math to figure out which way it is blocking the path, and then resize down by the width of the hallway and move over half of the width of the hallway to where it should be.

1 Like