NPC pathfinding logic

I have a pathfinding script that works fine but targeting is done by closest distance using Pythagoras. This is an issue when there are multiple floors or walls. Is there any way to determine the closest player without pathfinding every player? I loop the pathfinding every second to pinpoint the new location of the current target and it’s already inefficient

Does the game involve cooking in any way?

Not a restaurant tycoon :sweat_smile:
Horror game

If I’m interpreting this correctly, if you are computing a Path for every Player every second, it shouldn’t be resource intensive at all.

If you want to get the closest Player, you will still have to loop through every Player and filter them by distance (and filter line-of-sight via Raycast if needed). You can then use Path:GetWaypoints() to add up all the distance to get the shortest Path.

1 Like

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