1
\$\begingroup\$

I have a simple WebGL maze game and has problem with enemies overlapping when they are going to target position. Now i'm detecting there collisions, but dont know what to do with them when they are collide, if i choose to stop enemy when it collide with someone other - then when first enemy will reach target other will just stop one after another, so i cant use this solution. The perfect result will be if enemies will bypass other enemies, and i was trying to repel enemy in opposite direction from enemy with which it collides, but then i cant control it, and it could be repelled into the wall, or stuck between wall and other enemy. Could someone share the right solution? I dont need any code examples, i will be happy to hear your thoughts in theory

\$\endgroup\$
1
\$\begingroup\$

This is a very common problem in AI pathfinding, and you generally have three possible solutions:

  1. Accept the overlap. But this is far from ideal.
  2. Queue your enemies. Detect a collision, and stop the one behind, for up to half a second, then recompute the path and get it moving again. This is a simple, but very naive modification.
  3. Make your pathfinding aware of the position of your enemies. At the beginning of each AI "frame" update the map with the positions of each enemy. Treat these "maze cells" as blocked, and compute the path based on these additional blockages. Periodically recompute paths, and update the map as enemies are removed/added. If a valid path can't be found, wait a few frames for a path to open, and try again.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.