Without showing too much code and overcomplicating the question, basically, I am generating walls. Each wall has a start and end point (marked by the poles) Both the poles and walls are stored in tables.
I have code that checks for intersecting walls. This works, and detects where intersections are, and create a pole to mark the position.
The idea with splitting the wall is you go from the wall all being under 1 model as 1 wall, I check the intersection point and any wall that is beyond said point of the intersection gets put into its own separate wall.
local test = wall:GetPivot().LookVector:Cross(Vector3.new(0, 1, 0))
-- Transfer wall parts from 'wall' to 'WallModel'
for _, wallPart in pairs(wall:GetChildren()) do
if test.Z ~= 0 then
if wallPart.Position.Z < startPoint.Z then
wallPart.Parent = WallModel
end
end
if test.X ~= 0 then
if wallPart.Position.X < startPoint.X then
wallPart.Parent = WallModel
end
end
end
The main problem is that when you have a wall that requires several splits at once, it only detects the original wall and splits from there.
So basically, the wall is created, there are several splits in it, it detects all those splits, and splits all those walls it’s intersecting. However, that new wall that was just added isnt checked with the original loop.
I’m sorry, it’s really hard to explain, and I don’t want to just paste 400 odd lines of code. Hopefully someone knows what I am trying to accomplish and have a better solution?
I believe the code I have above is the main issue though and that my method for getting the intersection point isn’t right. startPoint is the intersection points position
Video example
As you can see, most of the walls are cutting correctly. But it’s missing some spots. Unsure if this is maybe how I am storing the poles and walls, but they should be storing correctly, just that the code above isn’t cutting them correctly
More help (hopefully)
So the cream wall is generated last. When generated, it detects 2 intersections. And when I test this time, it did Intersection 1 first (it appears to be random each time, whether it goes to the intersection of the left, or right)
And so it then splits
So OG wall is the original wall model, new wall is the one created, and the code above goes through OG wall, finds all the parts to the left of intersection 1, and puts them in New wall.
However, since the loop doesn’t take into account newly created walls, new wall doesn’t detect that there’s an intersection there. Reason I don’t detect new walls added is cause it broke the intersection system, so I have to only loop through the existing walls