Hello, I am interested in how to do a pathfinding with the support of multiple agents. The standard pathfinding behavior ignores other moving NPCs and they pass through each other.
Alternately enabling and disabling the obstacle behavior for them on each frame works extremely unstable, slow, and looks very bad visually, since both of these behaviors are not designed to be used together for 1 object.
As far as I understand, path finding algorithms can be very robust, support a huge number of agents and dynamically adapt the path for each one on the go, taking into account other agents and obstacles.
I figured out how to do it. The method is very simple, not very good in terms of performance and there are a number of minor flaws, not errors, but moments that require a little refinement so that the behavior of agents is more logical and advanced in individual scenarios. But it works, i guess.
Iβm attaching all the details and events with comments, in case you might need something similar in your project.
If one of the moderators sees this, should I request this feature? Updating the pathfinding system would be very useful, given that there are a lot of ready-made solutions on the Internet and they do not require creating an algorithm from scratch.
This is a very important and necessary feature, the range of applications of which is simply huge, literally any game in which there is more than 1 character who must dynamically find their way, and this is almost any game, as it seems to me.
Thatβs great work - Iβve bookmarked this as Iβve not really played about with pathfinding that much so far, but when i do, Iβll try to remember to come back to this as I like the way they separate - particularly when they take it in turns to go through the narrow doorway!
Here is a slightly updated version, this option works better. But this is still a draft, so there are probably redundant events or errors.
I did it more out of curiosity and Iβm not using it in the project yet, but I will update the post if I ever come up with a better option or bring this one to an acceptable state.
For those who might find this useful, hereβs a slightly improved version.
The problem with the old version is that even if you optimize it (by calculating routes for small portions of NPCs instead of all at once, or by simplifying the algorithm for off-screen NPCs, etc.), it still calculates very long paths, which can reduce FPS even if you have just 2-3 NPCs if their destination is very far away.
Therefore, itβs much better to use the βTravel to Random Positionsβ extension. With it, only the number of NPCs for which you calculate the path per frame matters; the path length can be any.
Hereβs the basic setup; itβs not optimized and calculates the path for all NPCs simultaneously. This works well for about 50 NPCs in a scene, but it could potentially be used for hundreds if you only calculate paths for 20-30 NPCs per frame, regardless of their total number in the scene: