In this lesson, you will learn how to use the Physics Debugger to visualize contact points and resolve unstable jittering in stacked physics objects.
Understanding Jitter
When you stack multiple Rigidbody objects, you may notice them vibrating or "jittering" even when they should be at rest. This often happens because the physics engine is constantly calculating micro-collisions as objects slightly overlap. When these tiny collisions fight against gravity, the objects bounce or jitter, creating visual instability.
Visualizing Contact Points
Unity’s Physics Debugger is your most powerful tool for diagnosing this. You can find it by navigating to Window > Analysis > Physics Debugger.
Once open, check the box labeled Visualize Contacts. When you run your game, you will see small colored dots appearing wherever two physics objects are touching.
- Green dots: Normal contacts.
- Red dots: Collisions that are currently generating force.
If you see a rapid flickering of red dots between two stacked objects, your physics engine is struggling to resolve the contact. This is your cue that the stack is unstable.
Resolving Stability
When you identify persistent red dots in a stack, try these steps:
- Check Collision Geometry: Ensure your colliders aren't overlapping at the start of the scene. Use "Primitive Proxies" to simplify complex shapes, as complex mesh colliders are prone to "bouncing" when they have too many contact points.
- Adjust Sleep Thresholds: If the objects are constantly active, they never enter a "sleeping" state. You can increase the
Sleep Thresholdin the Rigidbody component to tell Unity to stop calculating physics for those objects sooner. - Check Mass Ratios: If a very heavy object is stacked on a very light one, the engine often struggles with the math, leading to explosions. Keep mass ratios between stacked objects reasonable (ideally no more than a 1:10 ratio).
By visualizing these contact points, you move from guessing why your game is behaving erratically to seeing exactly where the simulation is breaking down.
Key Takeaway: Use the Physics Debugger’s "Visualize Contacts" mode to identify flickering red dots, which indicate areas where collision resolution is failing and causing jitter.