In Age of Mythology and some other strategy games, when you select multiple units and order them to move to some place, they make a "group" when they reach the desired location:


I have a Vector with several sprites, which are the selected units, the variables tarX and tarY are the target x and y. I just want an example, so you can just set the x and y position and I can adapt it to my code. Also, I would like to ask that the algorithm calls "isWalkable" for the x and y position, to determine if it's a valid position for each unit.


1 Answer 1


What you're looking for is basically coordinated movement. The units pathfind to their destination and when they reach it, they form a "formation".

This is a topic decently covered in the AI Game Programming Wisdom (Book 1, Book 2, Book 3 and Book 4) books. But, I'll refer you to the following articles:

Coordinated Movement - A link explaining the fundamental principles of coordinated unit movement in RTS games


Implementing Coordinated Movement - An article continuing from the first, that talks about how to implement this type of movement in a game.

It's written in C++ but it shouldn't be too difficult to port to any other language, as the underlying principles remain the same.

Hope that helps.


  • \$\begingroup\$ Okay, I'm gonna read it. I am using A* path finding. \$\endgroup\$
    – user4248
    Dec 27, 2010 at 21:00

You must log in to answer this question.