Zombie AI walks around their own hitbox

Hello developers,

I have an issue. The Zombies i made that work perfectly except they walk into eachother and not around eachother which i wanted to fix.
I tried working with pathfindingmodifiers, they work only the zombie walks around its own hitbox. Which i don’t want. I tried all kinds of stuff that did not work. Like having every zombie have a different costs label and changing the costs that did not really work out as i wanted because, costs dont get updated whenever a new zombie gets added or removed. Which makes the zombie not walk around the more recently spawned zombies.

This is a small part of my spawn function. For the pathfinding i use simplepath which is a community module.

function Zombie.new(name: string)
	local Model: Model = ZombieConfigurations.Model:Clone()
	Model.Parent = Zombie.SpawnFolder
	local Hitbox = Model:FindFirstChild("Hitbox")
	assert(Hitbox, "No hitbox detected please check zombie model [" .. name .. "]")
	local Modifier = Instance.new("PathfindingModifier")
	Modifier.Label = HitboxLabel
	Model.Parent = Hitbox
	local self = setmetatable({}, Zombie)
	self.Model = Model
	self.RootPart = Model:WaitForChild("HumanoidRootPart")
	self.Humanoid = Model:WaitForChild("Humanoid")
	self.Animator = self.Humanoid:WaitForChild("Animator")
	self.Humanoid.WalkSpeed = GetWalkspeed(ZombieConfigurations)
	self.Path = SimplePath.new(Model, {
		["AgentRadius"] = 1.5,
		["AgentHeight"] = 5,
		["AgentCanJump"] = false,
		["AgentCanClimb"] = false,

	self.Path.Visualize = debugMode

	table.insert(AllZombies, self)

	return self

This is a video of the problem to better explain it.
robloxapp-20231208-1826107.wmv (1.6 MB)

I don’t know if there is a good solution for this or if anyone else had this problem before. Anyways, if you got any idea please let me know!

1 Like

You could just use raycasts. They are really effective barely reduce performance if they do at all. All you would need to do is just fire of the ray then if it hits a hitbox or zombie it would make the current zombie move in a certain direction.

1 Like

You can give them 2 collision hitboxes infront of them, and then instead of going from waypoint 1 to 2 to 3, you go from 1 to 4 to 7 to 10 skipping a few. Then, if they touch anything with their collision hitboxes, just make them move away from the hitposition.

Here’s a document from Left 4 Dead about pathfinding zombies

1 Like

I was thinking of that, but was not sure if it would work. Ill try it anyways and see if it works.

I recompute the path every like 0.28 seconds. I dont get why you skip sertaint waypoints is that for performance or something else. The 2 collision hitboxes are a good idea. Although i dont know how it would work if they move with both of them against another zombie.

Well, because pathfinding can be choppy. This way it’s less choppy. Smooths out some of those waypoints in the middle

1 Like