Wrong collider on a procedural quad

I generate a procedural quad and I want to add a box collider to it.
The problem is that when I add the collider via script the collider is a default box collider (1x1x1) placed at the origin:

8120345--1052396--upload_2022-5-11_20-26-25.png

My code to attach the collider is:

            Collider wantTrigger = GameObject.AddComponent<BoxCollider>();
            wantTrigger.isTrigger = true;

And if I try to add manually a box collider on play on a rotated quad I receive this:

8120345--1052399--upload_2022-5-11_20-28-36.png

So I receive a bigger box collider because it doesn’t rotate with the mesh.

Someone can tell me how to apply via script a box collider to the plane in the right way?

The box collider can be offset and scaled.

It cannot be rotated.

To rotate a box collider to match your Quad, you would need a second GameObject (perhaps as a child?) with its Tranform set to have the necessary rotation to match the alignment of your geometry quad.

You could also perhaps use a MeshCollider and just feed the quad in directly. Note: MeshColliders only collide against the “outside” of the mesh, eg, the visible portion, so if the above is a flat one-sided quad, you’d need to duplicate the mesh faces to have it collide from either side.

If you’re interested in seeing other procgen stuff, check out my MakeGeo project:

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo

Perfect! Thank you so much!