I would like to, at some point, make bots that would act as teammates for my game in order to fill in empty space in matches and a separate game mode featuring waves of (many) enemies that one team must destroy. However, would the built-in PathfindingService be the best option for this or would something else be better? If your game contains bots/enemies (especially if you control a fairly large amount of them), what method(s) do you use? Thanks!
PathfindingService is the most efficient way to create AI on Roblox. I haven’t exactly encountered any issues with lag or other limitations while using it. I’ve been able to solidly control around 150 humanoids at a time with it with out any issues. But if you’re doing more you’re going to be pushing it to the limits.
Honestly i think this depends on how complex you want your bots to be and how much customization you want. in terms of efficiency the
Path-finding Service is fairly optimized for handling most tasks, but it lacks in the ability to customize it. if you were to make a bot to act as a teammate you would have to use more logic than just the path-finding service itself, you would have to add in some logistics. From my experience bots solely using the path-finding service tend to be “dumb”, they don’t have any or don’t have a great interconnection or sense of the game world.
if wanted to you could create your own path-finding system using some algorithms, one of the most popular, of which being the A-Star algorithm, can used along sides heaps to minimize the amount of resources needed to create a path. Along with this “Navigation Mesh”, using triangulation can be used .
if were looking for something more of an intricate and observable bot you can look more into neural networks, although it is a little more complex, it could pay off to a great extent.
i’m going to also provide a video by Crazyman32, that might be useful (it’s not exactly what your are trying to do but it still might help you generate some ideas)
Also here’s a useful topic to refer to for general questions about the path finding service:
Pathfinding service tends to be very performant; in my own experience, the bottleneck in performance has been due to the use of Humanoids in NPCs, rather than pathfinding calculations.
It would most likely not be worth it to use an alternative algorithm; (1) Lua is slow (your algorithm will require a lot of complex optimisation to be anywhere near the performance of pathfinding, especially if your map is complex), (2) it’s a very time consuming task, and (3) it will likely be much less accurate than Roblox’s for maps with complex 3D geometry, and if your map is reasonably dynamic, it’s effectively out of the question. The only use I see for a Lua-based pathfinding algorithm is if you have a map with simple geometry which is static, and you require more control over pathfinding (or need to run simple 2D pathfinding on a huge number of instances).
For my own NPCs, I mostly use pathfinding. If there is a direct path to the target (based on raycasting and a few calculations to make sure the NPC doesn’t fall), the NPC simply moves directly towards the target. I would recommend this because pathfinding can appear quite “jittery” and non responsive when the target is nearby, but you need to take measures to optimise raycasting when you have a large ignore list of other NPCs. I recalculate my paths quite often, but I take a lot of other measures to make sure all other calculations (like choosing a target player) are as performant as possible. My servers can handle around 100 NPCs before there starts to be noticeable lag, but this is only because of the obnoxious network bandwidth associated with using Hunanoids (the actual script performance on the server is still acceptable). Hopefully this can be alleviated when Roblox releases their new character physics controllers.
I’m sure roblox’s pathfinding service is the most efficient performance-wise, but it’s reaally bad at traversing obstacles from what I’ve seen. You can turn on navigation mesh to see where the pathfinding service will allow NPCs to walk. If the NPCs can’t walk to important parts of the map then it might be better to make your own pathfinding system, or just have them follow a series of set trails.
I highly doubt that an alternative pathfinding algorithm would be better at traversing obstacles than Roblox’s, especially if the map is dynamic. I have personally never experienced this issue: the problem is usually in the implementation, not the path service itself.
What I mean is this
The roblox pathfinding system won’t make a simple 7 stud long jump. But with simple raycasting and math you can make an NPC jump at least 11 studs. (I’m not saying the pathfinding system is bad, but it might be better to do something different, if NPCs can’t traverse the map with roblox’s built in service)
To add on to what people are saying here, if the PathfindingService is efficient, then it will have some shortcomings. If it was useful for specific cases, then it would probably have some issues with lag and would not be as fast as it appears to be now.
This is a common trait for Roblox objects in general - we get the basic parts/algorithms, and it is our job to tailor them to our needs. GUIs? We don’t even get round ones. Meshes? Make them yourself. Games? Pfft, that’s trivial.
The Roblox model is really giving us a lot of leeway by handing us the basic parts of game design. We have to put everything together, with all the details done ourselves. If you want to make your own PathfindingService, you can. But I think it would be best to work with the existing implementation and try to modify the way you use it in your game.