So lately me and my friend have being working very diligently creating a nostalgic wave defense game. Everything went well until we reached the game mechanic, determining what is the best way to create our AI.
Context:
Monsters spawn from spawn points and converge towards the center of the map. We’re trying to make the AI know how to actively reach players and having some form of intelligence to know when to jump in order to reach the client. (Somewhat similar to WenlockToad’s “Zombie Attack”) We plan on having 100+ monsters moving at once, however we can’t determine an efficient way for them to path to players without expending too much memory.
We’ve considered:
Creating our own humanoids
Using Roblox’s pathing system
Creating a very primitive waypoint system with bricks
Can someone suggest or give insight on which would be the best system to invest in?
What do you need that Roblox’s own PathfindingService can’t provide? It already allows NPCs to jump over gaps/obstacles to reach their goal. I think Zombie Attack uses PathfindingService, too.
40 possible pathfinding goals * 100+ NPCs is 4000 pathfinding operations to determine the easiest goal for each NPC to reach… Ouch. I agree with the above, if the built in pathfinder has the features you need and can handle load while maintaining a decent response time to changes, then go with it.
One optimization you can use reguardless of if you use the default pathfinder or build your own is computing the euclidian distance to a potential goal and making sure that it is smaller than the shortest known path to any goal. This will prevent calculating many paths which we already know must be longer than the shortest path.
If the built in pathfinder can’t handle the load or you need features it doesn’t have, then the optimization above can be taken further. If while calculating a path, the walking distance to the current point + the straight line distance the rest of the way to the goal becomes longer than the minimum known distance, then we can stop walking down that path. This, plus map specific optimizations should make your pathfinder much faster than the built in one because you can avoid large amounts of work that doesn’t need to be done.
(Edit: removed an extra line I couldn’t see when I typed up this response on my phone)