PathWalking, Stuttering on terrain

I’m trying to make NPCs walk around the terrain at random, some areas on the map have stuttering spots and I am unsure of the cause. I’ve tried growing, eroding, smoothing, flattening, and painting the terrain but nothing seems to work. I’ve tried adding more to the nav mesh but the problem appears to persist


https://gyazo.com/d717429a2acd75589ae62a3286aee93a

I was writing a solution but I thought it was a solution to the wrong problem. Whoops.

Anyways, I’ve encountered a few problems and its solutions while working with pathfinding on my game, so I think I’ll be able to help.

People will need more information:

  1. Are there any waypoints going underground? (might cause unreachable waypoints) (this happens often using Roblox terrain)
  2. Are you using Humanoid.MoveToFinished:Wait()? (this causes the usual stutter problem, more prominent in live server)

Waypoints going underground

Solution:

  1. Compare the current waypoint position Y-value with the previous. If the difference is extreme ( difference > 15 or difference < -15), use previous waypoint position Y-value
  2. (Ignore the compare at the first waypoint, since there’s no previous waypoint at that moment)

example

-- pretend there's a code to get waypoints here
for i, v  in ipairs(waypoints) do 
  local targetPosition = v.Position
  local diff = waypoints[i-1] and targetPosition.Y - waypoints[i-1].Position.Y or 0
  if diff > 15 or diff < -15 then
    targetPosition = Vector3.new(targetPosition.X, waypoints[i-1].Position.Y, targetPosition.Z)
  end
  -- do your 'move here' code using targetposition
end

.MoveToFinished:Wait()

Solution:

  1. Use polling.

example:

-- pretend there's a move here code up there
while (rootPart.Position - targetPosition).Magnitude > 3 do 
  task.wait(0.2)
end
-- pretend there's a 'stop here' or 'move to next waypoint' code here
1 Like