Avoid overlap of BoxColliders

Hi everyone,

I want to achieve that BoxColliders don’t overlap at any given time. Is this possible at all?
I am setting the new position using rigidBody.MovePosition() on a kinematic BoxCollider. The counterpart is a static BoxCollider without RigidBody (wall).
The following graphic illustrates the problem.

4509967--416881--Untitled-1.png

Cheers

Kinematic + MovePosition doesn’t react to collisions so you may move the rigidbody to any position. In order to prevent it to inter-penetrate other objects, you may first detect the overlap and then use ComputePenetration to find a non-overlapping position. Check out:

Physics.OverlapBox
Physics.ComputePenetration
Rigidbody.SweepTest (and its “All” variant)