Hello, I’m trying to create a move in formation system, like the systems in RTS games. So for example, if you select 10 units, they should move to a formation and move together as a formation to the destination point.
I already have kind of a solution, but I’m not happy with it. Basically I send every unit every tick to a position relative to the formation leader (not good!), and there are problems like, when should the Units go directly to the goal destination and when should they move to the formation …
So I’m interested, how would you create an RTS move in formation system?
I’ve never done it, but I’ll tell you as I imagine it:
you have an array of vectors that corresponds to your formation location settings (like 0;0;0 then 200;0;0 and so on and so forth)
when the move order is received, it corresponds to the world location of the player’s hit cursor, take that location
for each unit in the unit group, apply one of the index in your array of vectors to the stored location (verify if it’s a valid AI location, if not do something about it)
give each unit in the group one of the modified location to go to (AIMoveTo node directed to that location)
Hmm, I believe they’ll be disorganized only the first time they move. I admit that is not an ideal solution but I think you should try it out to see what results it gives you (if you have no other leads).
I think it is not easy with BP, you might need to expose some C++ only functions to BP.
in C++ it is possible to get a path for the leader (in BP only synchronously which has a high performance cost), then you can access the path and target follower units to the next node with an xy offset defined by formation rules (define a group width and unit distances, then it is easy to calculate on group/unit spawning in case of a line formation), and you can define group directions for path segments by the difference vector of start and end points, so you can rotate the xy offset of followers properly. your formation will look like a real formation only if followers do short pathfindings because of the navmesh shape. and in case of bottlenecks like gates or narrow corridors, the formation width must be managed to avoid units getting separated from the group.
Matrixes is a important word if you are going to do that.
Remember a Matrix it’s just an array of arrays. Formation( array ) { Leader } has Packs(Array){ Group leaders } that has LineOfTroops( Array ) { spread }