I’m creating a Zombie game. And I want to in theory have lets say 50 zombies in one area. The game doesn’t lag barely at all if they’re standing still. But once they collide with each other the FPS starts to drop. Is there a way I can disable them colliding with each other?
There would be a few ways of doing this. You could repeatedly compare positions, or magnitudes of positions of zombies within a certain radius. Using Region3 may also be an option (possibly the best), but I’m not sure how they react to being moved on a regular basis. If that doesn’t work, you could use some kind of hit part or raycasting to similar effect, but I’m not sure how efficient you could make it.
Just create a collision group for the zombies and have it collide with all groups except for its own group.
A zombie consists of multiple parts. Lets say 14 parts. Can collision filtering be used on entire models? Also these zombies wont be preplaced, so is there a way to add an entire model upon inserting/cloning to workspace?
Set all parts to the collision group before you clone it, then the cloned one will already be set up.
local PhysicsService = game:GetService("PhysicsService")
PhysicsService:CreateCollisionGroup("Zombies")
PhysicsService:CollisionGroupSetCollidable("Zombies", "Zombies", false)
local zombie = game.ServerStorage.zombie
for _, part in pairs(zombie:GetDescendants()) do
if part:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(part, "Zombies")
end
end
for i=1, 200 do
local z = zombie:Clone()
z.Parent = game.Workspace
z:SetPrimaryPartCFrame(CFrame.new(Vector3.new(math.random(-50,50),5,math.random(-50,50))))
end
Cool, what is the ‘SetPrimaryPartCFrame’ bit for?
Ohh, that’s just how I was teleporting the zombies for my little test script. That for loop just spawns 200 zombies in random locations between Vector3.new(-50, 0, -50) and Vector3.new(50, 0 50). You can really ignore the second for loop since that’s really just testing to make sure the code worked.
Ah right thanks!
/////////////