Don't get any collision by using OverlapBox

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

If you have scaled or rotated the transform of your car gameobject this could lead to problems. In your Raycast you check for a collider relating to a transform that is unscaled and unrotated.