kind of did it, the way it works now is, it makes the circle with a 8 way symmetry, so no more of those gaps, and in the end it checks if the game objects will not be on the same tile, by checking if x and z are equal to zero, and if it is equal to zero, it only instantiates the object by 4
known issues:
with certain values either the tiles overlap, or it creates a gap that is less than one tile meaning that the radius of the circle is not symmetric on 8 ways, only on 4.
public class test : MonoBehaviour {
public int Radius;
private int x;
private int z;
private int oldZ;
private bool dif2;
private bool dif1;
public float waitTime;
public GameObject wallTile;
public int size;
// Use this for initialization
void Start()
{
x = 0;
z = Radius;
oldZ = z;
dif1 = true;
if (size >= 0)
{
StartCoroutine(DrawCircle());
Debug.Log("size must be greater than 0");
}
}
IEnumerator DrawCircle()
{
int r2 = Radius * Radius;
Instantiate(wallTile, new Vector3(Radius-2, 0, 0), transform.rotation);
Instantiate(wallTile, new Vector3(-Radius+2, 0, 0), transform.rotation);
Instantiate(wallTile, new Vector3(0, 0, Radius-2), transform.rotation);
Instantiate(wallTile, new Vector3(0, 0, -Radius+2), transform.rotation);
while (dif1 == true)
{
bool difZ = false;
x += size;
z = (int)(Mathf.Sqrt(r2 - x * x) + 0f);
dif1 = z >= x;
difZ = oldZ - z == size || oldZ - z == 0;
if (difZ == false)
{
z -= size/2;
dif2 = (z - x) >= 0;
}
if (dif2 == false && dif1 == false)
{
StopCoroutine(DrawCircle());
}
if (dif2 == true && dif1 == true && x%2==0) //x%2==0 if it is odd
{
Clone();
yield return new WaitForSeconds(waitTime);
}
}
}
private void Clone()
{
transform.position = new Vector3(x, 0, z);
Debug.Log(z-x);
Instantiate(wallTile, new Vector3(transform.position.x, 0, transform.position.z), transform.rotation);
Instantiate(wallTile, new Vector3(transform.position.x, 0, -transform.position.z), transform.rotation);
Instantiate(wallTile, new Vector3(-transform.position.x, 0, -transform.position.z), transform.rotation);
Instantiate(wallTile, new Vector3(-transform.position.x, 0, transform.position.z), transform.rotation);
if ((z - x) != 0)
{
Instantiate(wallTile, new Vector3(transform.position.z, 0, transform.position.x), transform.rotation);
Instantiate(wallTile, new Vector3(transform.position.z, 0, -transform.position.x), transform.rotation);
Instantiate(wallTile, new Vector3(-transform.position.z, 0, -transform.position.x), transform.rotation);
Instantiate(wallTile, new Vector3(-transform.position.z, 0, transform.position.x), transform.rotation);
}
oldZ = z;
}
}