Hello I seem to be having some great deal of trouble making a box formation in game.
here is a code snippet of what I’am doing I just need help with logic to get it in a box formation… Been working on this for the past 2 days and I cannot seem to get them in a box… only Echelon Left.
void CreateFormation()
{
//Anchor the first position
SquadPositions[0] = Center.transform.position;
//Increment the currRow
for (int j = 1; j < SquadPositions.Length; j++)
{
//Next Row
SquadPositions[j] = new Vector3(SquadPositions[0].x,
100, SquadPositions[0].z + (j * flockSeperation));
for (int k = 0; k < columns; k++)
{
SquadPositions[j] = new Vector3(SquadPositions[j - 1].x
+ (k * flockSeperation)
, 100, SquadPositions[0].z + (j * flockSeperation));
}
RaycastHit hit;
if (Physics.Raycast(SquadPositions[j], -Vector3.up, out hit))
{
//Set the height of the squad position
SquadPositions[j] = new Vector3(hit.point.x, hit.point.y, hit.point.z);
}
}
}