How to make sure units KEEP formation while moving

Currently I can create formations, and when I set a destination I set it using the relative “origin” to make sure all destinations for the units in the formation stay the same. This works great they arrive and lign up in formation.

HOWEVER, If they need to move around a few obstacles on their way to the target, they break formation and just try to find the shortest route to the destination meaning they all end up in a long line hugging the obstacle.

This makes sense, but how can I make sure they dont break formation while moving? The only way I can think of is to assign them to a parent that does the pathing for them.

Hi

Formations are very tricky. Something that many games do is to assign a “leader”. All other agents in the group set their destination to something like estimated leader's position in 5 seconds + my desired relative offset in the group.

For a more advanced approach, I would recommend the chapter “Company of Heroes Squad Formations Explained” from the book “AI Game Programming Wisdom 4” which I think is available online.

I spent a month on such a script. I used completely different methods. My formation script has almost nothing to do with the pathfinding library, it only checks for the availability of the coordinates of the end of the path. I worked with coordinates, that is, at the end, the squad members must come to certain coordinates. The script assigns these coordinates, and then sends it further to the pathfinding library. Therefore, I do not have a leader, I have a central point of the squad, it is assigned from an available member of the squad, in the same script. There are no timers either.

Only it has not yet been properly tested.

In fact, this pathfinding library is much more complicated than such a script.

1 Like