Preventing Convex Mesh Colliders from Interpenetrating

I’m making a 2.5D puzzle game. As part of the game there are ice cubes that slide around, run into each other, and stack.

The ice cubes have a rigidbody that is is locked for movement on the Z axis and for rotation on the X and Y axis. Instead of using box colliders, I use convex mesh colliders that are basically cubes with the edges cut off. This is to stop the cubes from getting caught on stray edges in the environment. Avoiding getting snagged on stray edges is important. For example, if there’s a whole bunch of these cubes in a row and you want to slide another cube on top of them, the sliding cube can’t be getting snagged on the cubes below.

Here’s where the problem comes in. While for the most part behaviour is exactly what I want, occasionally the cubes will start to clip into one another, often rotating into the other cube. Eventually the interpenetration will stop and the cubes will “pop” away from each other, which is wildly disruptive to the puzzle design and a very ugly, obvious visual artifact besides.

I don’t want to have to use box colliders here because they work very poorly when the cubes are stacked, but this behaviour with the mesh colliders is unworkable. What might cause this, and how can I stop it? Alternatively, is there another way I could avoid the snagging behaviour that’s causing issues for me?

Here are some of the steps I’ve already taken:

  • I’ve verified that the mesh collider is actually convex in 3DS MAX
  • Unity mesh collider settings are set to Convex
  • I’ve changed the rigidbody collision settings from Discrete to Continuous and even Continuous Dynamic, but that hasn’t reduced the incidence of penetration.
  • I’ve verified that interpenetration happens even without the custom scripts I’m applying to the ice cubes.
  • The scale on the collider is not being changed at runtime, and is set to (1,1,1)
  • I’ve attempted to replace the mesh collider with a set of primitive box/capsule colliders in roughly the same shape, but the results weren’t good and snagging was a problem.

I’ve been making a 2D game using 2D ToolKit for a while now that also relies heavily on physics. Interpenetration has been a large problem for me, but I’ve noticed a pattern. Interpenetration seems to occur for me when the surface area of one of the colliders is too small. I originally had the problem with regular box colliders, I’d set the depth to something really thin as I figured the Z-axis wasn’t important. I fixed the interpenetartion issues here by increasing the Z scale of the boxes to 1.

I later ran into a similar issue when I made a triangle shaped mesh collider, if the triangle hit a surface with one of the pointy edges it wouldn’t rest on the surface but would jitter about. Like you I modeled the meshes with rounded corners and also increased the Z scale even further (up to 15 before it started to work properly). So maybe increasing the Z scale would fix your problem aswell, to increase the surface area for those narrow corners of the boxes.

The answer to that question was applicable to my situation.

I placed two box colliders inside the ice cube such that they were completely enveloped by the mesh collider but still were very close to the original shape. In this case,covering almost all the same volume except for the beveled edges, with a small .1 unit gap between the mesh collider and the new box colliders.

They ultimely “reinforced” the shape and prevented any interpenetration from going too far into the mesh. Since any interpenetration is minimal, the popping effect doesn’t happen, but I still get the advantage of the mesh collider not getting snagged on hard edges.