Question by
BlastBlockZoimon · Jul 28, 2018 at 06:53 PM ·
physics2dcollider2d
OverlapCircle not working correctly
//Spawn children
for (int i = 0; i < maxChildren; i++) {
while (touchingOther && tries < 100) {
tries++;
childSpawnPosTester.x = Random.Range (minX, maxX);
childSpawnPosTester.y = Random.Range (minY, maxY);
mutated = randomBool ();
if (!mutated) {
childSpawnRadTester = Random.Range (minChildStats ["radius"], maxChildStats ["radius"]);
} else {
childSpawnRadTester = Random.Range (minChildStats ["radius"] - (minChildStats ["radius"] / (Random.value * mutationMultiplier)), maxChildStats ["radius"] + (minChildStats ["radius"] / (Random.value * mutationMultiplier)));
}
if (Physics2D.OverlapCircle (new Vector2 (childSpawnPosTester.x, childSpawnPosTester.y), childSpawnRadTester) != null) {
touchingOther = true;
} else {
GameObject newChild = Instantiate (child, new Vector3 (childSpawnPosTester.x, childSpawnPosTester.y, 0), transform.rotation);
newChild.transform.localScale = new Vector3 (childSpawnRadTester * 2, childSpawnRadTester * 2, childSpawnRadTester * 2);
children.Add (newChild);
touchingOther = false;
}
}
touchingOther = true;
}
Sometimes Physics2D.OverlapCircle works and detects a collider but most of the time it doesn't. Is the radius of the circle wrong or is it something else? Btw, when I use rad in a variable name I mean radius, not radian.
Comment