Making complex objects settle under gravity

Hi all,

I’m trying to make piles of junk. :wink: For reasons I won’t go into here I need random piles of complex objects, and I don’t mind the time cost too much because they will only exist for a short time and the player can’t interact with them.

My question is how to make complex (often concave) objects settle into a plausible heap under gravity. From what I’m aware you can’t collide two concave meshes together.

My first thought is:

  1. Have a rigidbody and two colliders per object - a rough convex collider and a meshcollider.
  2. Start with all using convex colliders only (e.g. turn off meshcolliders).
  3. Drop the objects.
  4. After a little settling time run through the objects one at a time from the bottom to the top. Disable the rigidbody for the object, this is it’s final position. Enable their meshcollider and disable the convex collider so things above will settle. This would ensure no concave on concave collisions.
  5. After all objects have been run through, call the process complete.

I don’t think the results would be so pretty.

I have heard of other solutions simulating concave objects with jointed convex objects. I’m not sure how stable or performance hungry they are. Also do the physics solvers get more stable answers if you start near the solution or not?

Any help would be appreciated!


Use Compound colliders?

You can assemble standard colliders – mostly long cubes and capsules – to create an effectively concave collider. I’ve only done it with simple L and C shapes – well, a moving bowl made up of maybe a dozen cube “planks” – but seems to work fine.

I assume you could even use compound convex Mesh colliders. Like if you needed to build a shape out of wedges, say.

Rigid bodies have a freeze position option that might work for you. Example:
rigidbody.constraints = RigidbodyConstraints.FreezeAll;