- Home /
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-
https://www.dropbox.com/s/jssag7zadi0kxyr/Screenshot%202013-12-09%2018.30.26.png
One of the arrays highlighted to show overlapping-
https://www.dropbox.com/s/bl2s27p9433lv0l/Screenshot%202013-12-09%2018.31.55.png
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;".
Answer by Statement · Dec 10, 2013 at 12:05 AM
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.
Your answer
Follow this Question
Related Questions
How to set to game objects's position from 2 different game objects arrays equal to each other? 0 Answers
How to select an Game Object from an Item List 0 Answers
How can i get ONLY the childrens of a GameOnbject with GetComponentsInChildren method? 5 Answers
Read different game objects into array at same time? 2 Answers
C# Plane Detecting a Gameobject 1 Answer