Something I do to make the npcs not overlap each other is this function that checks the point in which the npc is moving to and checks if it’s occupied by another npc and adjust it accordingly
I can provide the function here.
function CheckSpace(RootP, pos)
if not RootP or not pos then return pos end
-- Get the primary part of the RootP
local RootP2 = RootP:IsA("Model") or RootP:IsA("Actor") and (RootP.PrimaryPart or RootP:FindFirstChildOfClass("BasePart")) or RootP
if not RootP2 then return pos end
local radiusX, radiusZ = RootP2.Size.X / 2, RootP2.Size.Z / 2
local slots = {
pos + Vector3.new(0, 0, -radiusZ),
pos + Vector3.new(radiusX, 0, -radiusZ),
pos + Vector3.new(-radiusX, 0, -radiusZ),
pos + Vector3.new(0, 0, radiusZ),
pos + Vector3.new(-radiusX, 0, radiusZ),
pos + Vector3.new(radiusX, 0, radiusZ),
pos + Vector3.new(0, 0, -radiusZ * 2),
pos + Vector3.new(radiusX * 2, 0, -radiusZ),
pos + Vector3.new(radiusX, 0, -radiusZ * 2),
pos + Vector3.new(-radiusX, 0, -radiusZ * 2),
pos + Vector3.new(0, 0, radiusZ * 2),
pos + Vector3.new(-radiusX, 0, radiusZ * 2),
pos + Vector3.new(radiusX, 0, radiusZ * 2)
}
--if not aware then aware = require(script.ChatbotAlgorithm.Awareness) end
local enemies = workspace.Enemys:GetChildren()--aware.Gettable("enemys")
local slot = 1
for _, enemy in pairs(enemies) do
local enemyRoot = enemy:FindFirstChild("HumanoidRootPart") or enemy:FindFirstChild("Head")
if RootP2 and RootP2.Parent and enemyRoot and enemyRoot.Parent and enemyRoot ~= RootP2 and enemyRoot.Parent ~= RootP2.Parent then
local enemyRadiusX, enemyRadiusZ = enemyRoot.Size.X / 2, enemyRoot.Size.Z / 2
--local conflict = false
--repeat
for _,slotPos in slots do
--local slotPos = slots[slot]
if (RootP2.Position - Vector3.new(slotPos.X, RootP2.Position.Y, slotPos.Z)).Magnitude < (radiusZ + enemyRadiusZ - 1) then
-- conflict = true
-- slot = slot + 1
else
--conflict = false
pos = slotPos
break
end
end
--until not conflict or slot > #slots
end
end
return pos or slots[math.random(1, #slots)]
end
This function organized the npcs around the target into a formation where the first 4 are in a + formation and it can handle up to 16 overlapping npcs before returning the original position.