Any Solutions to the Mesh Collider Overlap Problem?

Apologies if this a rehash of a familiar problem but I’ve searched extensively and haven’t found anything that’s helped me solve the following.

I’ve almost finished a fairly basic game in Unity to the point where I could put it on the Play store without feeling too embarrassed by my efforts. However, before I do so, I need to fix one problem that’s come to light.

The game uses physics which have, so far, worked well. However, almost as an afterthought, I added a new game mode in the last week and it has resulted in a problem I’d previously managed to avoid with colliders.

I’m using mesh colliders, but with very simple polygon hulls based on the actual mesh of the visual objects. They’re not moving at huge speeds but they do move fast enough to cause problems with occasional objects getting embedded inside a stationary collider. Sometimes two or three objects collide in a tight space and will overlap completely and they’ll then begin a slow dance as they try to disentangle themselves.

I’ve tried variations of Interpolate/Extrapolate with Static/Continuous/Continuous Dynamic collision detection. I’ve changed the PhysicManager settings for Min Penetration for Penalty, changed my Solver Iteration Count to 50. The game works really well on everything from my PC to tablets and my relatively old phone. I’ve even changed the speeds of the objects to make them move slower but I still occasionally get these problems with colliders overlapping, sometimes by up to 50% of their width/depth.

Does anybody have any ideas/suggestions? Is there something I’m missing? I know I could physically check the distance of each object from each other and set a minimum but I don’t know how to do that without interfering with the physics engine.

Have you tried lowering the fixed time step in Time? This makes Physics calculate more frequently. It increases CPU usage, but it gives you more accurate collisions. Try 0.01 for 100fps. The default is 50fps.

I assume you’re using rigidbodies. Is this 3D or 2D physics? I assume 3D since you say Mesh Collider.

Thanks for the reply Guavaman. Yep, I already had the time step pretty low but I lowered it again, though it didn’t seem to have a great bearing on the problem. It’s been a real headache but, in the end, I’ve had to add lines to my FixedUpdate to calculate the distance of object from the rest and to move them back to a previous point if there’s an overlap. [Fingers crossed] It seems to have worked for the very worst examples, even if it wasn’t the ideal solution I’d hoped for.

I’m just reaching here since there are so many variables involved, but how are you moving the objects? Modifying transform.position instead of using forces on the RB will cause you problems.

Another possibility is the world scale. If everything is really small, you could also have issues.

If you test with a simple cube/sphere/capsule collider do you see the same issues?

When they detangle themselves do they get thrown out very violently?

Pretty violently. They certainly do a dance as they attempt to untangle themselves and sometimes one will come flying away with unrealistic velocity. However, adding code in the FixedUpdate to prevent them getting too close seems to have stopped that. I assume it was a problem of objects moving too far in the course of a update cycle and the space between positions hasn’t been checked for collisions.

@ Guavaman. Ah, world scale. I wondered about that. Changing the scale might be a big job but I’ll see if it’s possible today. The game is almost finished and I just wanted to fix this one relatively minor issue.

And, yes, I’m not moving the objects. I merely apply a force and let the engine work everything out.

Convex/concave meshcollide problem maybe? Two concave meshcolliders wont react properly when colliding

Thanks, Frankrs. I didn’t know that about mesh colliders, though the problem’s been occurring between convex colliders. They’re quite simple shapes, in fact. Low poly hulls attached to higher poly models.

I’ve now altered the scale and the speeds and things seem to have calmed down. The game’s now pretty playable and I’ve not had a single dancing collider in an hour of testing. :slight_smile:

Just FYI, there is a Convex checkbox in the MeshCollider component in the inspector in case you missed it. You also want to make sure your colliders are completely sealed up, 3D (generally best if they’re not just planar), and don’t have any weird non-manifold edges and things like that. Just make sure they’re perfect geometrically in your 3D package by running an error check on them. (assuming you’re not creating them on the fly from the geometry.)

Glad to hear it! Try not to make them so big that you have to crank up gravity a bunch to compensate unless absolutely necessary. What was your original scale and what’s your new scale? I imagine to describe the intersection problems you’ve been having, your objects would be in the 0.1 to 0.5 size range.

Ah, I think you’ve hit the nail on the head. My objects were really tiny… Less than a 0.5 diameter in terms of world coordinates. It hadn’t been a problem but this is my first 3D project and I’d not really considered scale.

I’m now certain that was my problem. I’ve already been using the convex checkbox and I’ve been really careful about having good geometry since I’d read about the problems of holes in models. I’m wondering now if the scale has also been causing some very minor (but strange) problems with friction which has been causing some of my objects to veer away from a straight path.

Anyway, we live and learn. Thanks for the help. I thought I was going to be stuck with this problem. :wink:

@Valette

Awesome! Glad to help!

FYI, objects smaller than 0.5 are okay in some circumstances as long as they’re not moving too fast. In my experience, MeshColliders are much more fickle than primitive colliders. You can get away with BoxColliders a lot smaller than that usually.

Well, I’ve now managed to rescale my entire scene by a factor of 10 and all the physics have changed for the better. I’ll now have to retune my physics materials but I can already see a big difference. Even the trickier mesh colliders are colliding with no problem. I think you’ve earned a big thank you in my game credits!

@Valette Hehe thanks, but not necessary! :stuck_out_tongue: