My zombies are chasing the player and will eventually overlap. I know that using MoveTo always uses the same position point, but I don’t know how to fix it.
This is a video:
This is my script:
function AI_Monster.Follow(plrs,Monster,index)
local CloseChr
local Hrp = Monster.PrimaryPart
for i,v in pairs(plrs:GetChildren()) do
local Distance = (v.PrimaryPart.Position - Hrp.Position).Magnitude
if not CloseChr then CloseChr = v end
local CloseDistance = (CloseChr.PrimaryPart.Position - Hrp.Position).Magnitude
if Distance < CloseDistance then
CloseChr = v
end
end
if CloseChr then
Monster.Humanoid:MoveTo(CloseChr.PrimaryPart.Position)
end
I think the zombies from the toolbox tries to handle this by looking at the positions of the other zombies and adding a “repulse” force based on any nearby fellow zombies.
I’ve also done this in a different type of game where I had “attacking positions” in a grid around the player and the enemies would claim the nearest unclaimed attacking position.
So the closest enemy would get the front and center attacking position, the enemy towards the right would get the front right attacking position, an enemy towards the back could get assigned a barck right position. That makes it so they aren’t all trying to go to the exact same location.