Hey,
i’m trying to find a way, how to find out and then prevent collisions, before I spawn a prefab to a random location. My code, so far, looks like this:
void Start()
{
for (int i = 0; i < minimalCars; i++)
{
GameObject car = generateNewCar();
BoxCollider bc = car.GetComponent<BoxCollider>();
Vector3 halfColliderSize = new Vector3(bc.size.x / 2, bc.size.y / 2, bc.size.z / 2);
Collider[] hitColliders = Physics.OverlapBox(car.transform.position, halfColliderSize);
int j = 0;
while (j < hitColliders.Length)
{
Debug.Log("Hit: " + hitColliders[j].name + j + hitColliders[j].transform.position);
j++;
}
}
}
In the editor I can clearly see, that two spaned prefabs are colliding with each other, but the console won’t log any collision. The BoxCollider also has the correct size.
Can someone help me?
Greetings