# bounds not following the shape of the object

I am working on a physics simulation, and am trying to “fill” objects with small spheres. I am using Collider.bounds.contains to make sure it fills the object. Instead of making the object out of the spheres, it follows a rectangular area around the object.

``````        float x = obj_x;
float y = obj_y;
float z = obj_z;
Collider sape = GetComponent<Collider>();
x = sape.bounds.min.x;
y = sape.bounds.min.y;
z = sape.bounds.min.z;
bool ext = false;
while (ext == false)
{

Pos = new Vector3(x, y, z);

if (sape.bounds.Contains(Pos))
{
Instantiate(particle, Pos, Quaternion.identity);
}
if (z >= sape.bounds.max.z)
{
ext = true;
}else
if (y >= sape.bounds.max.y)
{
y = sape.bounds.min.y;
z += .1f;
}else
if (x >= sape.bounds.max.x)
{
x = sape.bounds.min.x;
y += .1f;
}
x += .1f;

}
``````

Yes you have discovered what `bounds` actually is. Bounds are better known as AABBs or “Axis-Aligned Bounding Boxes”. They look exactly like what your code is drawing. Boxes aligned on the world axes to facilitate the physics engine’s collision broad phase. They are not meant to capture the actual shape of the collider.

If you want to check if a given point is actually within the collider itself, you can do something like this:

``````bool IsWithinCollider(Collider c, Vector3 point) {
return c.ClosestPoint(point) == point;
}
``````

By combining your existing code with this function, you can draw only spheres that are within the collider itself.

1 Like