5
\$\begingroup\$

I'm making a roguelike in which enemies wander around the map until they're detected by the player. They each have random destinations, so sometimes their destinations conflict and they block each other in corridors.

Enemies can't go through each other

Is there any approach that can avoid this issue? Only idea I have right now would be to detect which ones are at the end of the "trafic block" and made them change destination until their path is free... But maybe there's a better design solution for this problem?

\$\endgroup\$
  • 1
    \$\begingroup\$ How wide are your corridors? Can you divide them into lanes of travel in each direction? If not, you may need to institute a kind of reservation system, where units can't enter a corridor segment until oncoming traffic has cleared the passage. \$\endgroup\$ – DMGregory Feb 2 at 17:16
  • 2
    \$\begingroup\$ Hoop Hop Showdown? \$\endgroup\$ – Theraot Feb 2 at 18:26
  • \$\begingroup\$ @Theraot I really want to see a game now where the dungeon goblins rock-paper-scissors to resolve disagreements and right-of-way. It's so precious. :D \$\endgroup\$ – DMGregory Feb 2 at 19:12
  • \$\begingroup\$ Perhaps have them group upon encountering each-other, so one follows or leads towards the others destination. Could perhaps do that temporary until there is enough space for the 'follower' to continue to their original destination. \$\endgroup\$ – Dennis Feb 2 at 20:22
  • \$\begingroup\$ Is it possible to have corridors that are 2 units wide? Do the areas outside of the corridors have enough room for enemies to queue up? \$\endgroup\$ – Pikalek Feb 3 at 14:49
1
\$\begingroup\$

Just have the units consider each other an obstacle with regards to whatever pathfinding algorithm you use. As it is a roguelike and not a real-time game, the performance hit is barely noticeable. As units will be processed one by one, they will simply "see" a "closed" corridor and decide to go elsewhere.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

The solution I ended up choosing is a simplistic one:

  • If monsters get blocked at any point, they try to find a free spot around them
  • Then they set that as their new destination, overriding the previous one
  • Then when they reach that point, the game will choose a new destination as usual, so eventually they will just go somewhere else

It ends up making it look like monsters wander around, and when roads are blocked they just go somewhere else, which is what I wanted.

Note that this doesn't happen when they have a specific objective like chasing the player, but only when they're roaming.

| improve this answer | |
\$\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.