Hey, in the game, I am having trouble calculating the correct movement for my multi-selected troops.
Currently, I have implemented the movement where troops would stand side by side in the end coordinate. They will align on the Z axis no matter which direction they're coming from:

However, instead, I would like them to know the direction they're coming from and align accordingly:

What would be a formula to calculate a direction and alignment like that?
Currently my logic is pretty dumb:
func moveSelectedSoldiers(raycast: Dictionary, soldierTarget = null):
var coord = raycast.position
var startZ = selectedUnits.size() / 2 # calculates the start Z pos from which to align
var unitZPos = coord.z - startZ
for idx in selectedUnits.size():
var soldier = selectedUnits[idx]
soldier.moveTo(Vector3(coord.x, coord.y, unitZPos))
unitZPos = unitZPos + 1
Thank you in advance