The Mesh Collider is not working as expected

Hi there, I’m a beginner to Unity and trying to create a dice game on it.

There is a problem that the dice kept running out from the dice cup while the cup was shaking. I’ve checked the setting of mesh colliders and also created a 4-sides box colliders to prevent the dice rolling out from it. However, none of them went well.

So I tried to apply “constraints” in the sprit to hold the dice in where it should be and it was still getting out eventually.

Here is the video: https://youtu.be/-5QqQqmv2uI

Appreciate any help. Thank you.

Your MeshCollider has the “convex” checkbox ticked, which it ain’t … a hollow cylinder is a concave shape:

But when you toggle that checkbox I guess you’ll notice the MeshCollider encloses the cup or has other weirdness about it. It’s best to approximate the collision geometry with multiple primitive colliders. The store has some assets to make building complex colliders out of primitives easier.

Also, since you can’t actually see the dice while the cup is shaking, why bother keeping them in the cup? You could simply spawn the dice at random angles when the cup is lifted and the dice should roll out. This provides you with the same randomness without having to bother simulating something the player doesn’t even see.

For audio, you can then just play a clickering sound at random regardless of dice present or not.

1 Like

Thank you very much, it really helps a lot. I’ going to give another try