Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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)?

share|improve this question
    
those two results didn't appear when I asked the question 0_o. I'll check it out –  Daggio Nov 15 '11 at 4:53
1  
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. :) –  Trevor Powell Nov 15 '11 at 4:54
    
This was of help when I got this problem: boids –  Tili Nov 15 '11 at 12:15
    
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. –  Jonathan Dickinson Nov 15 '11 at 12:30
add comment

marked as duplicate by bummzack, Tetrad Nov 15 '11 at 16:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

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.

share|improve this answer
    
this worth a try. thanks –  Daggio Nov 16 '11 at 2:42
add comment

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.

share|improve this answer
    
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. –  Daggio Nov 16 '11 at 2:43
    
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). –  ashes999 Nov 16 '11 at 12:26
add comment

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