Hey guys, I'm currently trying to solve a formation problem. Let's say I select a group of units (400), and I resize this formation to an either smaller or larger rectangle. Units should move and line up in formation accordingly to the new rectangle size. I've got that all up and running, but the issue is the optimization of these assignments.
I am noticing that units that used to be on the far left side of a row will now run all the way to the far right side of a row. This is probably due to their "indexing" in the formation, and when a rectangle grows and shrinks, this flat indexing may end up on the far end of a row or the beginning or the middle when I'm trying to make it so that a unit in the middle of the formation will still be in the middle of the formation (roughly) after resizing.
As a result, I've been trying to do some index reassignments that are spacially aware, such as divide the old rectangle's columns and rows by the new ones for each soldier.
I've also tried to deal with any collisions of assigning to the same position with a BFS system that looks incrementally forward in the formation until it finds an empty unassigned slot. This kinda worked, but now there are random gaps in my formation. I presume this is because the rectangles are not perfect fits to the number of men. A size 500 rectangle may be assigned to a 480 man selection, and thus there are technically 20 empty slots.
Have you guys come up with a better system? Everything I've listed above is purely experimental and I'm not sure if it's even the right way to go about the issue. I'm worried I'm over-engineering a solution to what could be a simple matrix problem.