Pathfinding pet, how to give it a smooth follow

I started making a pet system that uses the pathfindingservice to allow the pet to follow the person, however i am not sure how to make the following smooth, i have this code:

local PathFindingService = game:GetService("PathfindingService")
wait(3)
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Root = script.Parent:WaitForChild("HumanoidRootPart")
local HumanRoot = workspace:FindFirstChild("billyandme"):WaitForChild("HumanoidRootPart")
local Pathparam = {
	AgentRadius = 0.5,
	AgentHeight = 3,
	AgentCanJump = true
}
local hcf
Root:SetNetworkOwner(nil)

local function walk(hcf)
	local path = PathFindingService:CreatePath()
	local look = hcf.LookVector
	path:ComputeAsync(Root.Position,Vector3.new(hcf.x + (look.x*(-5)),hcf.y,hcf.z + (look.z*(-5))))

	local waypoints = path:GetWaypoints()
	
	for _,v in pairs(waypoints) do
		----[[
		local part = Instance.new("Part")
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Position = v.Position
		part.Size = Vector3.new(0.6,0.6,0.6)
		part.Anchored = true
		part.CanCollide = false
		part.Parent = workspace
		----]]
		
		Humanoid:MoveTo(v.Position)
		Humanoid.MoveToFinished:Wait()
		
		
		
	end
	print("Finished Walking")
end

while wait() do
	hcf = HumanRoot.CFrame
	if (math.abs(math.sqrt(((hcf.x-Root.CFrame.X) * (hcf.x-Root.CFrame.X)) + ((hcf.z-Root.CFrame.z) * (hcf.z-Root.CFrame.z)))) > 10) and (math.abs(math.sqrt(((hcf.x-Root.CFrame.X) * (hcf.x-Root.CFrame.X)) + ((hcf.z-Root.CFrame.z) * (hcf.z-Root.CFrame.z)))) < 100) then
		print("WALKING")
		
		walk(hcf)
		
	end
end

However the pet follows each line through so the overall movement is just following line by line it doesn’t look like a smooth curve. I tried using

repeat wait() until (Root.Position-v.Position).Magnitude <= 10

instead of

Humanoid.MoveToFinished:Wait()

This made the overall movement smoother but the face of the duck keeps flickering back as if its trying to follow an old path

1 Like

I also made some tests with Pathfinding, and I also noticed that my pet is following old paths when I recalculated the path. So I made a internal value for example: “BreakLoop = false” and made an “if statement” inside the old for loop to break the loop so the pet won’t follow any old waypoints and a new loop starts when recalculating a new path.
That helped in my case, I hope I could help you with the issue.