Stopping a path in pathfinding sevice?

Is there a way to stop a path with the pathfinding service? So for instance… i have an enemy npc, that will keep a certain amount of distance from the player because its a magic base npc, but there are many different kinds of npcs that all work off of this module code, so it has to be friendly with seperate values depending on the npc. That could just be done with:

Settings = {
    EvilWizardHaltDistance = 15
}

So essentially my thought would be to break the path when the npc gets close enough to the player, with something like :Stop(), but ik thats not a function in the Pathfinding service, so maybe a vector distance subtraction between the players humanoid root part and npc?

1 Like

Depending on how your handling your pathfinding, why not just break from a while loop when your close enough?

1 Like

Because its in a rendered step that needs to continue even if the path finding is ended. A while loop would really be expensive in a rendered step, wouldn’t it?

If foundTarget == false
–pathfind
Else
-found target
End

Why would you use RenderStepped? You could just use stepped or heartbeat. There isn’t really a reason for that, now is there.

I’m sorry… its not rendered step… i was having a brain fart, it is heartbeat.

If you’re running the pathfollowing function on Hearbeat, then you can just add a conditional statement into your Heartbeat function to check if your Humanoid (or next waypoint) is within the halting radius

if (humanoidPos - targetPos) > 15 then
    -- move forward
else 
    -- do nothing
end

You mentioned loops, but if you’re running on the Heartbeat event there is no need for loops, the heartbeat event essentially acts like a loop which fires every frame.

2 Likes