Help with some silly stuff,

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!

1 Like

What do you mean by center position?

1 Like

The position or CFrame that would be in the center of all the walls.
Sorry I forgot to specify lol.

If you have any more questions feel free to ask :]

1 Like

So basically the average center of all walls from a top view? Like a center of mass where you find the center of a collection of masses/objects?

1 Like

Yes that’d be it.

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)
1 Like