I recently restarted on my long time game development project and had a few questions about how to improve my games AI.

I am a little stuck on the best way to implement my Enemy path finding when there are multiple enemies that can collide with each other. Here is an example of the way my AI works at the moment.

The melee enemy has the following states:

Aggressive Attacking - Is in range of attacking player

Aggressive Stuck - Is trying to reach the player but blocked by a collision object

Aggressive Clear - Is trying to reach the player but is not blocked by a collision object

Passive - not currently looking for the player but if it moves in it's line of sight it will move to the aggressive state

Currently I am using a uniform tile system. Here is the basics on how the pathing works.





            MOVE TO PLAYER

I do this every frame. This seems to work ok, but things have got more complicated when I bring in multiple enemies. What would be the best way to achieve the following.

Find a path for the enemy to the player when there are multiple enemies that can all collide with each other? If I just call A STAR it won't work correctly as the other enemies who are collision objects are also moving.

Sorry I hope this made sense, any help would be great.

  • 1
    \$\begingroup\$ Have you tried adding the monsters as a non traversable tile in your A* ? \$\endgroup\$ – Felsir Sep 3 '16 at 17:53

You will need to augment your A-star search to keep track of when tiles will be occupied and in which direction the blocking AI is going.

If a path is temporarily blocked at the time it would reach this tile the A-star can pick an alternative path or the A-star completes but a free tile (with no AI planning on moving through) should be targeted instead to wait for the path to clear to avoid deadlocks.

If tiles are busy in the same direction the other AI does not need to stay clear of the path.

The waiting time vs detour time can be used to select what to do, this becomes part of the travel cost.

This requires marking tiles with potentially multiple "busy from tick X to Y in direction Z" and properly keeping track of changes (AI get killed, redirected, etc) to recalculate the path finding.

  • \$\begingroup\$ Thanks alot, I really like the idea you gave. Going to try write a version of it now! \$\endgroup\$ – David Sleep Sep 5 '16 at 7:00

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.