physics2d: destroy rigidbody2d when under large pressure(is squeezed)?

I want to make player dead under large pressure of other collider. So I wonder if there is a way to detect if a rigidbody2d’s collider is squeezed by one or more objects(meaning those objects penetrates this rigidbody2d’s collider). Or maybe this has to be achieved in some other way?
Thanks in advance!:slight_smile:

The Collision2D.relativeVelocity could conceivably be used to calculate force from a collision. You could use each one of these individually to determine if some threshold has been reached or accumulate multiple callbacks to detect opposing forces.

But what if , say a huge stone door moving very slow but will still crush the player into a sheet?..

You don’t use velocity on its own, you can use it multiplied by mass, after al, a ‘huge stone door’ isn’t huge if it doesn’t have a lot of mass. Alternately, if you don’t want to use mass for some reason, multiply it by some value on a script attached to the object.

You can use mass * velocity or mass * (velocity/fixed-time) to give you force (or time-integrated force)

I’ll be honest though, using relative-velocity isn’t the best approach and has its problems such as being in contact on one side with a static object and another side a dynamic object with the object in question not moving. The dynamic object would show some relative velocity however the side with the static object would show zero relative velocity.

We don’t current expose impulse forces applied by the solver but that is something that’s being worked on in the new GetContact API (some of which is available in the experimental preview #1).

thanks a lot! I guess I can use the mass*velocity method or some sensor tricks to achieve this.:smile:

just to share it:
I add a small trigger collider at the center of player box collider. So when Player is squeezed, the “squeezer” will penetrate box collider and touch the trigger and then Player object can destroy itself.