How Expensive Performance Wise is Pathfinding?

I have a pathfinding system for my game.

This system does NOT use Humanoids. It still uses the :CreatePath() function and :GetWayPoints() function to create paths using the Roblox PathfindingService.

In order to keep the pathfinding smooth and accurate, it gets new WayPoints and computes a new path every 0.5 seconds or so. The target is expected to move, so it must do this to reach the target.

I’m just wondering, how performant is the default Pathfinding service? Is it worth turning off the pathfinding entirely and relying on a “beeline” movement if the agent is close enough to the target?

How many pathfinding functions can I have active at once before lag starts?

Thanks.

3 Likes

Pathfinding can be pretty performance intensive for longer paths.

I’d recommend using a raycast or shapecast to check for line of sight and moving directly towards the player if the NPC has a direct line of sight and is within 6-8 studs. This will be way more performant and will also look much smoother than half-second path updates at that close of a range. (assuming you don’t have anything the NPC needs to jump over)

I’d also recommend keeping track of what the player’s position was when you calculated the path, and only remaking the path if the player has moved more than 4 studs. You should probably skip this check when the NPC is within 15-ish studs and don’t have line of sight, just to make sure it can properly navigate to the player.

1 Like

if your game have 2D grid you can use A* pathfinding, it’s very performant, especially used alongside with parrerel luau and maybe even native code, you can also split code across the frames to remove stress