[2D Physics] Stop BoxCollider2D Sticking to Vertical Walls
Solution
Unity 2021.x - Unity 6.3.x
Published 7 days ago
A BoxCollider2D is observed to exhibit sticking behavior when interacting with walls, particularly when combined with a SphereCollider2D on the same GameObject. This interaction leads to unintended halts or immobility against surfaces during vertical or horizontal traversal.
To prevent 2D colliders from sticking to walls, apply a Physics Material 2D with zero Friction to the BoxCollider2D and set Rigidbody2D detection to Continuous.
To address instances of 2D collision sticking, a Physics Material 2D should be assigned to the BoxCollider2D component. The properties of this material can be configured to minimize Friction, which is often a primary cause for colliders becoming momentarily adhered to environmental geometry.
- Create a
Physics Material 2Din your Project window. - Set the Friction value to 0.
- Assign this material to the Material slot on your
BoxCollider2Dor theRigidbody2Dcomponent. - Adjust the dimensions of the
BoxCollider2Dto be slightly larger than theSphereCollider2D. This configuration ensures the spherical collider does not make direct contact with wall surfaces, allowing the Friction-less box to manage the primary collision. - Set the Collision Detection property on the
Rigidbody2Dcomponent to Continuous to increase precision and prevent objects from sinking into geometry.
Additional Tips
- Use a
CompositeCollider2Don your environment tilemaps to eliminate internal seams that catch on colliders even with zero Friction. - Consider replacing the dual-collider setup with a single
CapsuleCollider2Dto provide smoother interpolation over uneven surfaces.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.