Search code examples
c++game-enginegame-physicspath-finding

Group of soldiers moving on grid map together


I am making RTS game and whole terrain is like grid ( cells with x and y coordinates). I have couple soldiers in group (military unit) and I want to send them from point A to point B ( between points A and B is obstacles ). I can solve for one soldier using A* algorithm and that is not problem. How to achieve that my group of soldiers always going together ? (I notice couple corner cases when they split and go with different ways to the same destination point, I can choose leader of group but I don't need that soldiers going on same cells but by leader, for example couple at right side, couple at left side if it is possible). Was anyone solving similar problem in past ? Any idea for algorithm modification ?


Solution

  • You want a flocking algorithm, where you have the leader of the pack follow the A* directions and the other follow the leader in formation.

    In case you have very large formations you are going to get into issues like "how to fit all those soldiers through this small hole" and that's where you will need to get smart.

    An example could be to enforce a single line formation for tight spots, others would involve breaking down the groups into smaller squads.