Pathfinding help for NPCs

I’d like to make my NPC move from point A to point B first, then move to point C to carry out a supposed function, afterwards it’ll head back to point B and to point A.

I do understand pathfinding to a certain extent, but I’m not sure how to apply it for such a scenario. I’ve tried agent costs but it doesn’t seem to work. I don’t want the NPC to take a shortcut.

1 Like

you can make an array of checkpoints to loop through and use pathfinding agent on each point like this:

local destinations = {PointA,PointB,PointC,PointB,PointA}
for _,destination in pairs(destinations) do
 local waypoints --insert your pathfinding code here
 for _,point in pairs(waypoints) do
   Humanoid:MoveTo(point.Position)
   Humanoid.MoveToFinished:wait()
 end
end
2 Likes

Thanks. Didn’t know that you didn’t have to use path and could just use positions instead. Much appreciated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.