NPC Pathfinding jittery/stuttering walk animation solution

After encountering this issue myself I couldn’t find any solutions that worked for me by searching for it on the DevForum, methods such as setting the NPC Network Ownership did not work either, so after trying to figure out a solution myself I came up with this one and I wanted to share it with anyone that is having similar issues.

For this tutorial I’m using SimplePath, a great Pathfinding module which I am also using in the game I am working on.

This code is just an example of what to do, should work with the Roblox pathfinding with minimal changes

local isWalkPlaying = false -- Used to make sure the walk animation doesn't play on loop because Running fires many times with Pathfinding.
local isPathfinding = false -- Used to make sure that Pathfinding isn't running anymore and the script can continue to play the idle animation.

Humanoid.Running:Connect(function(speed) -- Listen for the Running event which returns the speed of the character.
	isPathfinding = NPC:GetAttribute("Pathfinding") -- Get the current state of Pathfinding attribute.
	if speed > 0 then -- If Speed is greater than 0 then the walk animation can continue.
		if isWalkPlaying == false then -- Check if the walk animation is already playing.
			runAnimation:Play(.2)
			idleAnimation:Stop(.2)
			isWalkPlaying = true
		end
	elseif speed <= 0 and isPathfinding == false then -- Checks if the NPC is still pathfinding/walking to the point, if not it plays the idle animation and stops the running animation.
		idleAnimation:Play(.2)
		runAnimation:Stop(.2)
		isWalkPlaying = false
	end
end)

Path.Reached:Connect(function() -- Detects when the NPC has reached the target position.
	NPC:SetAttribute("Pathfinding", false) -- Sets pathfinding Attribute to false.
end)

NPC:SetAttribute("Pathfinding", true) -- Sets the Pathfinding attribute to true to prevent Idle animations from playing.
Path:Run(targetPosition) -- Pathfinding function from SimplePath.

What you need to do is add a “debounce” for the code, detect if the walk/run animation is playing or if is the NPC currently pathfinding

Place file with the whole code:
pathfindingExample.rbxl (77.8 KB)

Before:

After:

19 Likes

NPC.HumanoidRootPart:SetNetworkOwner(nil)

3 Likes

This is one of the solutions that did not work for me and many others, the before video already has the network ownership set to the server but the issue is still there.

Edit to the main thread:
I’ve added an example file with the module and the script in it.

2 Likes

well yeah :SetNetworkOwner(nil) is a physics task manipulation type stuff. you failed to debounce your animation .Running runs when you move and when you stop if you dont have conditions set to stop the animation from playing both times itll result in jitters.

3 Likes

Relating to the doubce and stopping the animation , can us agg where and what would be added to the script ?

Thanks !

1 Like

Thanks bro I had the same issue that’s now solved after reading your post
0627DEMO

4 Likes

for me, it’s the same despite adding the script or smth, it stutters either way, even with SetNetworkOwner, I need to make all the parts masless to make it work, which is kinda bad.

1 Like