I've got group movement implemented pretty much like this:


Basically, that's combining path following and separation. It works nicely as long as units are in transit, but arrival does not work very well at all.

Right now, units just cease to use the path following component once the "exit" the path, i.e. when their closest point on the path is on or past the end.

This leads to those units bumping into each other and also overshooting the point the player clicked. Ideally, I'd have the units arrive scattered around the finish point (and reasonable close to each other), not all clumped up past the finish line.

I'd imagine that some kind of arrival steering might work here, but based on other units and a "fuzzy" classification of the end of the path.

Is there any proven way to do this?

  • \$\begingroup\$ You want something like the way soldiers move in a RTS? \$\endgroup\$ – wolfdawn Oct 6 '12 at 14:28
  • \$\begingroup\$ Yes, this is an RTS movement question, but I already got the moving - I need the stopping without bumping into each other ;) \$\endgroup\$ – ltjax Oct 6 '12 at 14:33
  • \$\begingroup\$ Related: gamedev.stackexchange.com/questions/28146/… \$\endgroup\$ – MichaelHouse Oct 6 '12 at 15:59
  1. Shorten the last part of the path by the radius of the area the units will occupy when they stop moving. You can guesstimate this based on the 2d size of the units and their number. Increase this approximation by 1.4-1.7x to prevent overlapping.
  2. Randomize n points that do not overlap around in the destination where they will stand.
  3. Sort the points by their distance from the last point on the path.
  4. When the nth unit arrives at the end of the path, move it in a linear path to the nth most distant point in the collection you randomized and stop them. ie : The first will stand at the most distant point, the second at the 2nd most distant.
  5. You should now have them standing scattered around the destination.

In order to randomize points that do not overlap and are not organized, take the destination and split it into spots for 2 or 3n units and then remove spots randomly.

I added some images for illustration:

Units in move

enter Stopping area

Divide it to spots

randomly remove spots

enter image description here

enter image description here

  • \$\begingroup\$ When do you do this? Not all units might survive the trip... So I cannot plan this ahead. I need something that works a little more locally... \$\endgroup\$ – ltjax Oct 6 '12 at 14:57
  • \$\begingroup\$ That is not necessarily true.. you just plan enough space, so basically if less units arrive that is fine. You still let the first unit take the 1st most distant spot, the 2nd, the second one and so on. \$\endgroup\$ – wolfdawn Oct 6 '12 at 15:06
  • 1
    \$\begingroup\$ There is a problem, if soldier A goes to point (5,0) and soldier B to point (4, 0) (where 4,0 is closer to their initial position than 5,0), and soldier A is somehow delayed (slowed by some ugly, spitting creature) he will arrive after soldier B and could be blocked by him. I can't come up with a working solution to this problem different than "position soldiers loosely enough". \$\endgroup\$ – Markus von Broady Oct 6 '12 at 15:28

You can combine multiple steering behaviors to get the result you want. You'll want to implement the arrival behavior. And combine it with the flocking behavior.

Select a "lead" unit. Whichever unit is in the lead works well. When you're using arrival, the arrival point for all other units in the group will be the lead unit position. The lead unit will be using the destination as it's arrival point. This will be sort of like a follow the leader situation. The lead unit will arrive at the destination and the other units will attempt to approach the lead unit.


You say you already have code to let the units avoid each other while in transit, so why not just keep that part of the code active even after reaching the goal?

In fact, to keep the units from clustering too tightly at the destination, you may want to increase the preferred separation for each unit as they reach the goal, so that they'll move out a little and give room for new arrivals.


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.