Search code examples
unity-game-enginecollision-detectiongame-physicsrigid-bodiescollider

Unity3D: stack of thin boxes toppling despite perfect alignment


Here is what happens when I copy&paste a few thin boxes, and then vertex-snap them to the ground and each other:

enter image description here

Pressing "Play" leads to the stack toppling.

I tried reducing the BoxCollider y to 0.99 and 0.95. No luck still.

Does anyone have recommendations to easily get a stacked wall to just stay up (until a real force is applied)? Maybe there is some sort of "glue" component to prevent two faces separating until a force exceeds some threshold?


Solution

  • Try setting their positions manually so that they are right under each other.

    You shouldn't expect to be able to make a stack of 20-30 box colliders stacked on their smaller faces because of physics simulation inaccuracies, floating point errors and so on. If that's your intention and/or the above doesn't work, try using Fixed Joints with a manually set Break Force and/or Break Torque.

    You can also try increasing the Solver Iteration Count to something like 10 or 15 (which should do the trick in most cases), but it won't be good for performance in scenes with 1000s of objects.

    Increasing the Sleep Threshold will also help in this specific case, but can cause problems like small objects sleeping when they have small (but not infinitesimal) velocities.

    EDIT: A similar thing happens with my own custom physics engine. Another workaround you can do is to align the bodies and set them to sleep in Start. That way they'll stay upright (not moving rather) and topple when something collides with them.