Pathfinding NPC seems to be hopping?

I’m using the Patrolling NPC script from the wiki and for some unknown reason, the NPC seems to be hopping in the game (as seen in the provided gyazo link), whilst in the studio the NPC is walking smoothly.

I do not know what could have went wrong.

http://wiki.roblox.com/index.php?title=Making_a_Patrolling_NPC

5 Likes

Looks like its because it is walking to each point, instead of directly to the destination, which cuts the walking animation short. So its not jumping, but just stopping the walking animation too soon. You could try spreading the points out so they aren’t so close to each other.

As a player you can replicate this by pressing W repeatedly to move forward instead of holding it down.

I noticed that tutorial isn’t using ComputeSmoothPathAsync which is what I used when testing a Goblin NPC that follows the player when the player gets within a certain range, but I am sure thats not necessary to fix the issue you are having, I just personally prefer that over FindPathAsync.

Edit: and I just realized that is depricated. So ignore that last bit.

1 Like

Try setting AutoJumpEnabled in the humanoid to false.

Did not work, the NPC is still walking funny.

I still cannot get this to work :frowning:

Just so you know, AutoJumpEnabled is only functional on mobile, and only on player characters, not NPCs. I have no idea why the property is under the Humanoid and not the player, as it’s restricted as such.

I believe Dev_Ryan is on the right track here,
It does seem like it’s walking to each point and then moving to the next, causing it to briefly stop. To prevent this you can remove the “humanoid.MoveToFinished:Wait()” but add a distance variable that continuously updates within the loop and then once the NPC reaches a certain distance (using magnitude to detect the distance between the NPC’s Primary Part and the waypoint) from that point, move it to the next. This will make it smooth, and keep it on track to avoid obstacles, but you may need to adjust the distance. Here’s an example if I didn’t explain it greatly.

local distance 
for waypointIndex, waypoint in pairs(waypoints) do
	local waypointPosition = waypoint.Position
	humanoid:MoveTo(waypointPosition)
    repeat 
        distance = (waypointPosition - humanoid.Parent.PrimaryPart.Position).magnitude
        wait()
    until
        distance <= 5
end	 

May not be the most efficient way to do it, but it’s how I do it when working with Pathfinding NPC’s, and it works well.
Hope it works for you!

12 Likes

Try this, could be the same issue.

1 Like

Sometimes it still hops but it’s bearable now.

That’s better! Did you try messing with the distance?
Instead of 5 try replacing it with larger or smaller numbers and see if that helps?

Thanks I will do that!

1 Like

No problem! If that doesn’t solve it completely then I’m not too sure sadly. :frowning:
Hopefully that works, and hope whatever you’re working on goes great! :slight_smile:

The problem has been solved but I will give this a shot also perhaps it makes it smoother.

1 Like