So I'm working on an RTS game and I'm trying to set pre-defined positions for units using my own formula. It takes the list of units and makes a position for each one in an array. The array then goes through a for loop which offsets each x position so units don't collide. The problem is that the Y and Z components are set to 0 whenever I try to get them to move. I'm not sure why because I'm not touching them.
Here it is:
Selected units list if you needed it
public static List<GameObject> SelectedUnits;
void MakeFormation(RaycastHit hit)
{
Vector3 origin = hit.point;
float Separation = 10f;
Vector3[] positions = new Vector3[SelectedUnits.Count];
for(int i = 0; i < positions.Length; i++)
{
positions[i].x = origin.x+Separation*i;
}
MultiSelect(positions, origin);
}
And the function that actually gets the units going
void MultiSelect(Vector3[] positions, Vector3 origin)
{
Debug.Log(SelectedUnits);
if (SelectedUnits.Count > 0)
{
for (int i= 0; i < positions.Length; i++)
{
Debug.Log("Moving group to area: " + positions[i].ToString("F4"));
}
for(int i=0; i< SelectedUnits.Count;i++)
{
Debug.Log("Index: " + i);
SelectedUnits[i].GetComponent<NavMeshAgent>().SetDestination(positions[i]);
}
}
}
```