So today is finally the day I have to tackle a task that has stumped me for a while.
Basically what I need to do is go through a table of walls and see if they are all connected to each other (like touching each other) and I would then like to get the center position between all of the walls.
The question is how? I have no idea where to begin when doing this, so any ideas to do this would help a load! Thanks!
This shouldn’t be too hard, it’s just getting the average positions of all the walls
here’s a possible implementation
local walls: {[BasePart]: true} = {}
local sum = Vector3.zero
local count = 0
local function add(wall: BasePart)
if walls[wall] then return end --wall has already been taken into account
sum += wall.Position
count += 1
walls[wall] = true
for _, touching in workspace:GetPartsInPart(wall, someOverlapParams) do
if checkIfIsAWall(touching) then
add(touching)
end
end
end
add(path.to.first.wall)
print("Average position of all touching walls is", sum/count)