Possible Duplicate:
Is there a simple way to stop enemies standing in the same spot?

So I'm making a game in AS3, it's a strategy DotA-like game (for flash game equivalent, there's UDE) so far so good, I have the A* pathfinding algorithm all sorted out and the minion units move to the desired location as I want them to be. The problem a rise when a unit stops in a node that has already occupied by another friendly unit. Both (or more than two) of them stacks up in one location, it looks like they're one unit.

I want to add collision detection so when they collide they don't stack up together. But now they stop when they collide on they way to a node. This isn't good because they won't move at all midway (they won't respond to enemy attacks like that). I've added a deltatime so they only stopped for 2 seconds before they move again to their designated designation. This moves them again but they flicker. Not how I want it.

So, like the title said. How to make more than one units don't stack up in a node? And if possible, how to make them not flicker while moving (it's good if they can tell other friendly units on the way and avoid them accordingly)?

  • \$\begingroup\$ those two results didn't appear when I asked the question 0_o. I'll check it out \$\endgroup\$ – Daggio Nov 15 '11 at 4:53
  • 1
    \$\begingroup\$ I only went searching because I vaguely remembered them from long ago. They used completely different keywords, so the system wouldn't have found them automatically. :) \$\endgroup\$ – Trevor Powell Nov 15 '11 at 4:54
  • \$\begingroup\$ This was of help when I got this problem: boids \$\endgroup\$ – Tili Nov 15 '11 at 12:15
  • \$\begingroup\$ One way I have seen it done is using a clean repulsive force (opposite of gravity) once a unit reaches its destination. The units bunch up together and then spread out nicely within a second or so - a behaviour I have seen in a few AAA titles. \$\endgroup\$ – Jonathan Dickinson Nov 15 '11 at 12:30

Not 100% on the best way to avoid your problem, but the first thought that comes to mind is maybe have a "feeler" radius around each unit. This feeler circle would detect if any other unit (friendly or not) is within the circle and act appropriately. I.E. stop if the unit is a friendly unit, and maybe walk around to the side of it so they line up uniformly, or attack if the unit is un-friendly.

As I said, just the first thought that came to mind.

Good luck. Cheers.


If you're using A* path-finding (or something else which is pretty quick), and you're detecting the paths multiple times (not just once on startup/creation of your map), simply mark any locations which have units in them as non-walkable and let the path-finder work around them.

This will require pretty much constant recalculation of your paths, so make sure your performance doesn't sink if you decide to do it this way.

  • \$\begingroup\$ Yes, I search for path multiple times in every few seconds, there are hundreds of nodes in one level with tens of units going from one node to other. If each unit detects the path each loop, it's surely gonna eat up resources. \$\endgroup\$ – Daggio Nov 16 '11 at 2:43
  • \$\begingroup\$ You might want to go with something simpler then, like a one-off check for each unit if the place they're walking into is occupied by another unit. That might be "good enough." But path-finding really is the "right" solution here (units avoid other units). \$\endgroup\$ – ashes999 Nov 16 '11 at 12:26

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