How to fix choppy / delayed pathfinding chase?

I’ve looked around and still haven’t found a solution to this. If you know what the issue is lmk.

local function walkTo(where)
	local success, errorMessage = pcall(function()
		path:ComputeAsync(model.PrimaryPart.Position, where)
	end)
	
	if success and path.Status == Enum.PathStatus.Success then
		for _, waypoint in path:GetWaypoints() do
			humanoid:MoveTo(waypoint.Position)
			humanoid.MoveToFinished:Wait()
		end
	end
end

local function findNearest()
	local nearest = nil
	for _, obj in pairs(game.Players:GetPlayers()) do
		local char = obj.Character
		if not nearest then nearest = obj end

		if (model.HumanoidRootPart.Position - char.HumanoidRootPart.Position).Magnitude <= (model.HumanoidRootPart.Position - nearest.Character.HumanoidRootPart.Position).Magnitude then
			nearest = obj
		end
	end	

	return nearest
end

while true do
	rs.Heartbeat:Wait()
	walkTo(findNearest().Character.HumanoidRootPart.Position)
	model.HumanoidRootPart.breath:Play()
end

And people say to remove humanoid.MoveToFinished:Wait()
but if i do the pathfinding would just start acting like humanoid:MoveTo(), running into walls and not acting like pathfinding at all.

Perhaps only skip humanoid.MoveToFinished:Wait() if a raycast from the enemy to the player isn’t obstructed. This way, if it is in a direct line of sight, it will constantly walk in the direction the player. Once there is a wall obstructing it, it will wait until it navigates around the obstruction.

I’ve not worked with pathfinding yet, so this is all just theory.

1 Like

Nope, tried this was still choppy.

I got it working by using one of my older chase pathfinding scripts.

1 Like

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