Controll squeeze of rigidbody between static collider and kinematic rigidbody.

Hi. Is there a way to detect and controll if a rigidbody is beeing squeeze between a static collider and a kinematic rigidbody?

This is my setup: I got a nonkinematic rigidbody as player. It lives inside of a box of static colliders. Those are the absolute boundaries in which the player is allowed to move. Furthermore I got kinematic boxes moving with rigidbody.MovePosition. They are able to push the player arround which is intended. However if the player gets stuck between the moving box and the boundary, he will be pushed throug the static collider and leave the allowed area.

How can I detect if this is happening or how can I tell the player to be pushed through the moving box rather than the static collider? Is there an easy way to do this or do I have to force him by script (would be harder to handle than simply setting colliders)?
Thanks in advance.

If i’m understanding you well, you might need to use the following script which can be found here.

This script is used to stop objects going through other objects (generally due to large forces created).

In your case, attach the script to your character. Add a new layer and you can name it anything, such as ‘Boundary’. All objects making the boundary put them in this layer. In you character inspector find you script and select the layer ‘Boundary’.