OnCollisionEnter sensitivity

I’m creating a casual basketball game and I’m having a hard time configuring the colliders sensitivity.

More specifically: I put a mesh collider on the rim to detect if a swish (only net basket) is scored, but even when the ball seems to pass right through without touching anything, OnCollisionEnter triggers on the rim.

For example, in the screenshot, when the ball falls vertically the collider triggers. Is there a way to adjust the sensitivity so that it doesn’t?


There’s no concept of sensitivity in this matter. Either an object entered a trigger or it didn’t. It’d be easier to help you if you provided some images with the actual shape of mesh collider and its configuration in the inspector.

That said, I bet this is the root of your problem: I think you’re using your mesh collider with Convex and Trigger turned on. Rings are concave shapes (i.e. non-convex). To make a mesh collider work as a trigger, you must have turned on the “convex” option. Convex meshes are those where a line can be drawn between every pair of vertices without going outside the mesh; so a mesh with a hole like yours doesn’t fit the category, and its hole will be ignored.

Here are two possible solutions:

  1. Use multiple box colliders make up the shape of the ring. You’ll likely receive multiple trigger callbacks, one for each collider that was triggered, so your code will need to be able to ignore the extra calls.

  2. Use a cylinder trigger that covers the complete basket hole. Then, in your trigger callback, measure the distance from the ball to the center of the cylinder: if the distance is small enough, the mesh wasn’t touched. I’d prefer this solution because it’s cleaner and allows you to easily add other functionality. For example, now you can change the distance-to-center threshold according to difficulty settings. You can also use the same collider to detect all kinds of stuff, like the speed of the ball, or if the ring is being touched.

Thanks for the detailed answer, Oscar.

Sadly, I’ve already tried adding box colliders around the rim and I had the same issue. By the way, I’m using OnCollisionEnter, not OnTriggerEnter, so my rim mesh collider isn’t marked as convex/trigger. Moreover, when the ball falls directly in the middle, OnCollisionEnter is not triggered so the hole is not totally ignored.