Getting better collisions with rigid bodies/environment

Physics is a complex system, and often misused because misunderstood.

Best practices summed up

The best practice concerning the physics environment and rigid bodies could be summed up in a few simple rules:

  • try to use primitives (such as boxes or spheres) or convex hull instead of triangle meshes for the shape type attribute of the rigid bodies;
  • if using triangle meshes anyway, take care of the faces normals, and increase the physics substeps in the Physics Locator;
  • if some ragdolls go trough very small collisions objects, increase the physics substeps in the Physics Locator;
  • if some ragdolls hit collision objects at a very high speed and go trough, increase the physics substeps in the Physics Locator;

Best practice trough a simple case

Let's consider one wants to create a cup that should hold falling ragdolls, and let's look at all the small things that might occurs while preparing an environment or rigid bodies to use with a ragdoll simulation.

Triangle mesh with wrongly set normals

The easiest way to make such a scene is to create a sphere, delete the upper half, and use the object as a Crowd Rigid Body. Once done, here is the result:

The first thing to check is the face normals. Switch the display on from the Maya menu:

In our case, the normals as facing outside the sphere, while the collision engine consider a face should collide with an object only if the normal is facing the object. Reverse the normals thanks to the maya menu:

Triangle mesh

Now that the triangle mesh is fixed, the collision detection is working, but most of the ragdolls are still going trough the cup.

The reason now is that triangle mesh collision detection is the most difficult one to handle with physics. The best is to use something else that triangle mesh (see the Convex Hull part at the end of the page), but if one really needs a triangle mesh, then the best is to increase the frequency of the physX solver by increasing the Physics Substeps in the Physics Locator parameters.

The result is now fine, but if you try it by yourself, you'll realize that the simulation framerate decreased by a factor of ten.

Sadly, that's the best solution if you really want to stick with triangle mesh.

Convex hull / primitive

But if you really want to achieve correct results AND a correct framerate, the best is to use convex hulls instead of triangle meshes.

If your environment is already convex, then all you need to do is to select the convex hull in the Crowd Rigid Body parameters, but if your asset is not convex (like my cup), then you'll need to do a little bit of Maya work to convert it in a set of as many convex meshes as you want.

Concerning the cup, faces were grouped by 4, detached and separated before being extruded, and here is the result:


The cup with the convex hulls (white stripes) that approximate its shape

The result is now quite better, and the simulation framerate is far better (the substeps value has been set back to 3)

Hence the list of best practices that were given at the beginning of this page.