Making an array "spread" out evenly?

How do I properly make an array “30x30” of planes are spread out evenly? The one and only issue i’m having is that the planes are overlapping each other by 3 units. How do I properly make sure the planes are butted up to each other and not overlapping?

General array while game is running-

One of the arrays highlighted to show overlapping-

Array Code:

public void grid_array ()
{
     for (int x = 0; x<grids_x; x++) {
          for (int z = 0; z<grids_z; z++) {
               GameObject grid_plane = GameObject.CreatePrimitive (PrimitiveType.Plane);
               grid_plane.renderer.material = pgrid_mat;
               grid_plane.transform.localScale = new Vector3 (0.5f, 1f, 0.5f);
               Vector3 grid_vector = new Vector3 (x - 15, 0, z - 15);// grids_x & z = 30 and I want the array to be centered.
               grid_plane.transform.position = grid_vector;
               Debug.Log ("Grid Draw: " + grid_vector.ToString ());
              }
       }
}

EDIT:

The answer to fixing this was just add “*5” to the end of “grid_plane.transform.position = grid_vector;”.

1 Answer

1

You need to take the size of each plane into account.

  • They are 10x10 units.
  • You scale them to half the size.
  • Position them 5 units apart

Example:

Vector3 grid_vector = new Vector3 (x - 15, 0, z - 15);
grid_vector *= 5;

> You need to take the size of each plane into account. Yea I had a feeling this was the case. I tried multiplying both grids_x & grids_z by different numbers to see if that would work. I didn't try doing anything to "grid_plane.transform.position = grid_vector;". Quite interesting that the only thing I needed to do was this "grid_plane.transform.position = grid_vector * 5;". I appreciate the help! Ill make sure to add the answer to my OP.