Best way to have a bunch of pathfinding NPCs move around?

What’s the most efficient method of having a bunch of NPCs walking around?

  1. What do you want to achieve?
    I want to have a bunch of NPCs walking around

  2. What is the issue?
    Lag and Pathfinding
    I don’t want NPCs to be walking into walls, trees, etc.

  3. What solutions have you tried so far?

  • Path finding service
    Caused a lot of lag
    (maybe because I was making a bunch of paths all the time?)
  • Tween Service
    Makes Physics irrelevant

I just wanted to get some insight into good and proper methods for achieving this.

shameless plug:

1 Like

Depending on what you’re trying to achieve with your game, you have multiple options.

If you have preset NPCs and know exactly what you want them to do, you can each give them individual routes to avoid obstacles.

Pathfinding generally should not be causing an insane amount of lag, but assuming you’re calling it a ton of times for each individual NPC that will cause lag. Try reducing the amount of times the NPCs move around and perhaps have a single individual controller that gives multiple NPCs the same route, or only run the pathfinding service for one NPC at a time.

Be smart about how you use pathfinding, do not simply put a pathfinding script in every NPC that runs endlessly every few seconds. I highly recommend one single controller that only that only gives movements to a few NPCs at a time

2 Likes

Well, depending on the amount of NPCs well vary the amount of lag, you could set a specific path for the NPCs.

You can use TweenService for that. You can have a part that marks the start/end. There are many tutorials on start/end moving parts. NPC would be no different.

1 Like

What is your current path-finding scheme? Are you just using Pathfinding service every second on every NPC? Do you have some sort of Pathfinding cache for grouped NPCS? Any optimizations you have done so far? More info is needed on what you have tried.

After joining your game for a few seconds, it looks like you have lots of grouped NPCs walking together. If you are running full pathfinding for every single entity, you are going to have major inefficiencies.

2 Likes

Perhaps you should control all the NPCs via a Main script.
Use some tables and functions and it should be optmized.

2 Likes