You need to tell them, that they should not aim/head for the leaders position, but for an position that is offset to the left or right (offset = whatever space an unit occupies), if the middle spots are already taken and therefore blocked.
So the right one should aim for a spot one orc unit right to the leader, while the left ones should aim for a position one orc unit left to the leader.
Until a spot in the middle becomes free and available.
Same if your group gets bigger, and you have more rows, just increase the offset by whatever they are currently offset to the left or right in the group. Just like in every group march ^.^
Is there a way to solve it on a collision level? Make it less bouncy. The solution you propose has too many special cases to consider.
If you are doing RTS game with AI coded in blueprints (instead of blackboard), make stress test see how many units you can handle at once. Also for RPG, do such test.
Blueprint only AI works fine up to about 50-100 units, then it lags. Esp collision and animation. are heavy on CPU with bigger number of units
This is reason blackboards were implemented, to make more units that 50 or so.
Use blackboards if that is case for your game.
And formation is only matter of getting leader world location, getting its forward and right vector, then some simple vector math.
For formations (with vector math):
Store all formations in arrays of offsets, each unit gets offset that is relative to leader orientation (forward and right vectors multiplied by some distance from leader.
Then you get leader position and add that vector to target of formation member.
To change formation read different row from array.
Hi! Thank you for your answer. I see i defined the problem in the wrong way. I’m not trying to do a group formation nor a RTS game, this was just the easiest way to present the issue. It could have been 3 players moving alongside towards the same point, i’d get the same result. (I’m making a click-to-move MOBA).
There were some attributes on the movement component like “max depenetration with pawn” and “max depenetration with pawn as proxy”. Was hoping that playing with them would give me better results, but i had no luck.
Personally, i wouldn´t even bother with collisions for formations. I would bring in something, where the general positions for different formations are stored (or build a formation manager), then you would only need to know, how many troops are in your current group/formation, and they then just need to figure out, which number they are in the choosen formation and walk to that position, relative to the current formation leader and his direction.
Then you can even give special units (like healer) special places in that formation (like center, surrounded by grunts), and they will choose the position depending on their function and number.
Aaand if you have several groups marching in formations or legions, then i bet, the army already have some schematics, where the leader of all those smaller groups should be (followed by their groups) in that bigger marching order ^.^
Go for blackboards and EQS if you are not using them. There are some built in functions in EQS that would help your code with overlapping target points.
Do movement and basic logic in blackboard and more complicated functions in blueprints/C++.
Here, i tested a very simple formation manager (which does not manage at all, currently the leader just fires events in his minions to choose position in the current formation ^.^ ), just as i have described here:
Snake Head will be followed by those Xenon 2 Balls, and they get their position from 2 Formation components, were some Arrow components define the position in that formation:
No collision checks, no jitter, all position relative to the leader. I just didn´t bother to implement a smooth movement during formation change, they currently teleport to the new position.