Help with making pathfinding smoother?

function GoToPoint()
	local torso = script.Parent.Parent.Parent.Torso.Position
local endpoint = script.Parent.Value
local hum = script.Parent.Parent.Parent.Humanoid
local path = game:GetService("PathfindingService"):FindPathAsync(torso,endpoint)
local points = path:GetWaypoints()

if path.Status == Enum.PathStatus.Success then
	for i,v in pairs(points) do
		hum:MoveTo(v.Position)
		hum.MoveToFinished:wait()
		if v.Action == Enum.PathWaypointAction.Jump then
			hum.Jump = true
		end
	end
end
end




script.Parent.Changed:Connect(function()
	if script.Parent.Value ~= Vector3.new(0,0,0) then
		GoToPoint()
	end
end)

this pathfinding script works very well except I noticed something annoying.
the NPC using this tended to constantly slow down and speed up making its movement look laggy. I didn’t realize its because with the pathfinding it slows down when it reaches a waypoint before going to the next. is there something I can do to make movement smoother? perhaps change how far apart waypoints are?

3 Likes

I tried your script and I didn’t see anything wrong, it seemed to go at a consistent speed. Could you provide a video of whats going on? Do you have a lot of other humanoids in your game? That could be why it seems laggy. Do you any other scripts that are taking a lot of computing power that could be slowing things down? Try looking at the Script Performance tab while your game is running and see how much each script is using

is there a way for me to upload a video without the dev forum saying its too big?

don’t make the video as long, I only need to see the part when its lagging

so I found a solution to the problem which would have not been considered should my game have been different. I lowered the mass of the NPC as well as remove all friction and this seemed to have fixed the stopping/moving. and because the game is space themed this behavior is desired. I also discovered that my method for FindPathAsync() is depreciated and I have corrected the problem by using FindPath(). what should I do at this point in terms of marking a solution?

4 Likes

mark your most recent post as the solution since you found it and reported it

Try setting network ownership of the rootpart to nil, low mass humanoids might cause a bigger headache down the line.

Also, MoveToFinished has a weird yield so I’d suggest checking Magnitude instead. Usually that’s the cause of stuttering in pathfinding.