Issue with wall system and acute angles

Hello!

I’m currently trying to polish off my wall placement system but I have ran into a very specific problem that I’m not sure how to fix.

So, I want to detect the intersection’s outer walls so I know where to place an extra part so there’s no weird gap. The problem with this is that when I place a wall that’s shorter than the previous wall and at an acute angle, it seems to detect the outer wall incorrectly.

Here’s my “logic”:

-- quadrants:
	-- 2 1
	--  |
	-- 3 4
	if wall2RelativeToWall1.X > 0 then -- 1 or 4
		if wall2RelativeToWall1.Z < 0 then
			quadrant = 1
		else
			quadrant = 4
		end
	else -- 2 or 3
		if wall2RelativeToWall1.Z < 0 then
			quadrant = 2
		else
			quadrant = 3
		end
	end
	local partFromWall1, partFromWall2
	if quadrant == 1 then
		partFromWall1 = wall1:WaitForChild('Part1')
		if intersectingWallPoint2.Name == '1' then
			print(1)
			partFromWall2 = wall2:FindFirstChild('Part2')
		elseif intersectingWallPoint2.Name == '2' then
			print(2)
			partFromWall2 = wall2:FindFirstChild('Part1')
		end
	elseif quadrant == 2 then
		partFromWall1 = wall1:WaitForChild('Part2')
		if intersectingWallPoint2.Name == '1' then
			print(1)
			partFromWall2 = wall2:FindFirstChild('Part1')
		elseif intersectingWallPoint2.Name == '2' then
			print(2)
			partFromWall2 = wall2:FindFirstChild('Part2')
		end
	elseif quadrant == 3 then
		partFromWall1 = wall1:WaitForChild('Part2')
		if intersectingWallPoint2.Name == '1' then
			print(1)
			partFromWall2 = wall2:FindFirstChild('Part2')
		elseif intersectingWallPoint2.Name == '2' then
			print(2)
			partFromWall2 = wall2:FindFirstChild('Part1')
		end
	elseif quadrant == 4 then
		partFromWall1 = wall1:WaitForChild('Part1')
		if intersectingWallPoint2.Name == '1' then
			print(1)
			partFromWall2 = wall2:FindFirstChild('Part1')
		elseif intersectingWallPoint2.Name == '2' then
			print(2)
			partFromWall2 = wall2:FindFirstChild('Part2')
		end
	end
	makeTestPart(partFromWall1.Position, Color3.new(1,0,0))
	makeTestPart(partFromWall2.Position, Color3.new(0,1,0))
	print(quadrant, partFromWall1, partFromWall2)

The issue happens only when the second wall is shorter than the first, not if the first wall is shorter than the second, and only if it’s at an acute angle.

As you can see here, red (placed first) has the dot on the right side whereas the green dot (indicating second placement) is placed incorrectly, on the wrong side of the wall.
Screen Shot 2021-09-07 at 8.29.08 PM

On my other attempts where this really specific things isn’t happening, the dots are placed correctly.

Screen Shot 2021-09-07 at 8.31.11 PM

I’m considering switching to another method because this is a dealbreaker for me, if nobody can offer a solution that is.

TIA for any help!

1 Like

Ended up just raycasting from one wall to the other to find what walls were inside and which were outside.

1 Like

I have experienced this problem time and time again. The less technical way to do it would to simply change the size of the other wall in order to compliment the size of the first wall. However even then the issue sometimes still occurs.

2 Likes