Pathfinding not pathfinding

I have a problem with my zombie pathfinding. Again. It doesn’t actually pathfind, and just runs into walls.

local function spawnArm(player)
	local clone = arm:Clone()
	clone.Parent = folder
	clone.PrimaryPart.Position = positions[math.random(1, #positions)].Position + Vector3.new(0, 1, 0)
	clone.Hitbox.CFrame = clone.PrimaryPart.CFrame
	clone.PrimaryPart.Appear:Play()
	
	task.spawn(function()
		wait(15)
		
		if clone.Parent ~= nil then
			print("Zombie has escaped!")
			local savedArmCFrame = clone.PrimaryPart.CFrame
			clone:Destroy()
			
			if zombie:FindFirstChild("HumanoidRootPart") and zombie:FindFirstChildOfClass("Humanoid") then
				local char = player.Character or player.CharacterAdded:Wait()
				local zombieClone = zombie:Clone()
				zombieClone.Parent = folder
				zombieClone.HumanoidRootPart.CFrame = savedArmCFrame
				zombieClone.HumanoidRootPart:SetNetworkOwner(nil)
				
				--[[zombieClone.HumanoidRootPart.Touched:Connect(function(hit)
					local hitHum = hit.Parent:FindFirstChild("Humanoid")
					local isPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
					
					if isPlayer and hitHum then
						removeZombies()
						print("Zombie touched! Stopping game..")
					end
				end)]]--
				
				local path = PFS:CreatePath({
					AgentRadius = 2,
					AgentHeight = 5,
					AgentCanJump = false,
					AgentCanClimb = false,
					WaypointSpacing = 3
				})
				
				while char do
					if zombieClone:FindFirstChild("HumanoidRootPart") and (char ~= nil) and zombie:FindFirstChildOfClass("Humanoid") then
					
						path:ComputeAsync(zombieClone.HumanoidRootPart.Position, char.HumanoidRootPart.Position)
						local waypoints = path:GetWaypoints()
					
					
						for i, point in pairs(waypoints) do
							zombieClone.Humanoid:MoveTo(point.Position)
						end
						
					end	
					
					wait()
				end
			end
		end
	end)
end

Do i make it compute a new path when it fails?

Try waiting for the zombie to finish moving with zombie.MoveToFinished:Wait(). If that doesn’t work then try making the zombie jump if the waypoint action is jump (Ik you specified it can’t but the zombie seems like it needs to jump…)

1 Like

When i used MoveToFinished:Wait(), the pathfinding did not follow the player smoothly.

Probably because the Waypoint spacing is too large?

1 Like

I tried putting it at lower numbers and it still wasnt smooth :slightly_frowning_face:

Strange, because my pathfinding works perfectly fine while waiting… Do you need the agent params?

Sure.

Debugging time then. Make a bright ball at every waypoint’s position to see if the path is even being computed properly.

Edit: Try moving the zombie only if the path status is success

Yes, the path is being computed correctly around the gravestone.

use :MoveToFinished:Wait() and dont use pathfinding when theres nothing obstructing the path between the player and the zombie
if you still want to use pathfinding for everything, theres a good module that can handle it all for you called SimplePath that u can run in a loop like this:

while true do
   SimplePath:Run(GoalPosition)
end

heres the link if u wanna try it out:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.