Wall corner extending problem

Hello,
I have recently made a wall creating system that works pretty fine but generating the corners between two walls are so much pain…
I have figured out a solution for that which is clearly not “prefect” for my case

As you can see below i run up into these kind of problems:

Here is the preview of the code where cornering comes up:

local function InstantiatePart()
	local part = Instance.new("Part")
	part.Anchored = true
	part.CanCollide = true
	
	local m = Instance.new("BlockMesh")
	m.Name = "BlockMesh"
	m.Parent = part

	
	return part
end

function GenerateWall(props)
	local part = InstantiatePart()
	part.Name = "Wall"
	
	part.CFrame = props.CFrame
	part.Size = props.Size
	part.Color = props.Color
	
	
	return part
end

function Make2Sided(part)
	local cf = part.CFrame
	local size = part.Size
	
	local m =Instance.new("Model")
	m.Name = "WallSides"
	m.Parent = part.Parent
	
	local side1 = part:clone()
	side1.Size = side1.Size - Vector3.new(size.X/2,0,0)
	side1.CFrame = cf * CFrame.new(side1.Size.X/2,0,0)
	side1.Parent = m
	side1.Name = "InsideWall"
	--side1.BrickColor = BrickColor.Red()
	
	local side2 = part:clone()
	side2.Size = side2.Size - Vector3.new(size.X/2,0,0)
	side2.CFrame = cf * CFrame.new(-side2.Size.X/2,0,0)
	side2.Parent = m
	side2.Name = "OutsideWall"
	--side2.BrickColor = BrickColor.Green()
	
	for _, corners in pairs(part:GetChildren()) do
		if corners.Name:sub(1,6) == "Corner" then
			corners.Parent = side2
		end
	end
	
	part:Destroy()
	
	return m
end

--CONNECTING WALLS
function getWallPoints(wall)
	local fp, bp
	fp = wall.Position + wall.CFrame.lookVector * wall.Size.Z/2
	bp = wall.Position - wall.CFrame.lookVector * wall.Size.Z/2
	return fp, bp
end

function EdgesNearby(OEdge, FEdge)
	local r = false
	local mag = (OEdge - FEdge).magnitude
	if mag <= 2 then
		r = true
	end
	return r
end

function ConnectPoints(wallCopy, pA, pB)
	local length = (pA - pB).magnitude
	
	local p = wallCopy:clone()
	p.Parent = wallCopy
	p.Name = "Corner"
	p.Size = Vector3.new(p.Size.X*2, p.Size.Y, p.Size.X*2)
	p.CFrame = CFrame.new(pA, pB + Vector3.new(0.00001,0,0)) --* CFrame.new(-(p.Size.X*2)/4 + p.Size.X/2,0,0)
	return p
end

function FindEdgeConnections(wall, walls)
	local frontPoint, backPoint = getWallPoints(wall)
	
	--loop through other walls
	for _, other in pairs(walls:GetChildren()) do
		if other ~= wall then --skip self	
			if other:IsA("Model") then
				--Decide wether the corner be inside the wall or outside
				--Inside or outside
				other = other.OutsideWall
			end					
			local connectionNeeded = false
			local connectPointA, connectPointB
			
			local nam = "Back"
			
			local otherFP, otherBP = getWallPoints(other)
			if EdgesNearby(frontPoint, otherFP) then
				connectionNeeded = true
				connectPointA, connectPointB = frontPoint, otherFP
				nam = "Front"
			elseif EdgesNearby(frontPoint, otherBP) then
				connectionNeeded = true
				connectPointA, connectPointB = frontPoint, otherBP
				nam = "Front"
			elseif EdgesNearby(backPoint, otherFP) then
				connectionNeeded = true
				connectPointA, connectPointB = backPoint, otherFP
			elseif EdgesNearby(backPoint, otherBP) then
				connectionNeeded = true
				connectPointA, connectPointB = backPoint, otherBP
			end
			
			if connectionNeeded then
				local wallThickness = wall.Size.X
				local wallHeight = wall.Size.Y
				connectPointA = connectPointA
				connectPointB = connectPointB
				if other:FindFirstChild("Corner_"..nam) == nil then
					local corner = ConnectPoints(other, connectPointA, connectPointB)
					corner.Name = "Corner_"..nam
				end
			end
			
		end
	end
end

remote.OnServerEvent:Connect(function(player, mode, ...)
	local args = {...}
	if mode == "GenerateWall" then
		local wProperties = args[1]
		if wProperties.Size.Z > 1 then
			local wall = GenerateWall(wProperties)
			local house = workspace:FindFirstChild(player.Name.."'s House")
			local WallsFolder = house.Structure.Walls
			wall.Parent = WallsFolder
			local EdgeConnections = FindEdgeConnections(wall, WallsFolder)
			
			Make2Sided(wall)
		end
	end
end)

If you do not understand the code and need some explanation please let me know

Basically
• Generate wall at given position and size
• Detect if it needs any cornering and do it
• Make the wall 2 sided (outside and inside parts)

1 Like

Have you looked at the resizealign plugin? You might find some code snippets that would help.

No, never heard of it before actually

I can’t believe it helped and worked as i needed it to! Thank you for suggesting me the code and HUGE thanks to the writer of that code :heart:

1 Like

Well, actually almost worked…

This happens at extreme angles
And i tried to fix it with manyaly resizing walls and this…seems unfixable by just resizing
https://gyazo.com/031b1b0f15d43267a1e9ba5719c4e1e1

1 Like

Have you tried using wedges to fill in the corners?

1 Like

Thought of but couldnt think of the formula of it :confused:

Well, it wouldn’t really be a wedge, but a triangular mesh scaled at 1x1x1 studs. You’d get the opposite edges of the walls (add or subtract half the width as well as adding or subtracting half the length to get the edges), that would be the width of the triangle. Then, find the distance from the edge to the centre and that’d be the height of the mesh. I’m probably bad at explaining but hopefully you can understand what I’m trying to explain.

The problem here is that it would not make walls sharp conrnerred
Say for example a wall has 90 degree angle
Adding wedge to the gap will make the corner flat and not sharp…

1 Like

Check out the Gapfill Plugin. It that might be of use for filling in the corners. Also made by Stravant.

I have made my own gap fill, and same as i said before it is like using wedges for the corners
therefore flat corners…which is not what i want :confused:

Bad:

Good:

So in this case below i have a cornered model near the experiment of desired result
but instead i get this:
https://gyazo.com/ed42520b73d31a9f2c75a4b2388fd921

How am i going to fix this?

It is kind of like this:

Angles mater, how do i get information about angles??

1 Like