Testing for Rigidbody Crush

Setup:
I have spherical rigid-body objects moving around a 2D world just fine. The player has the ability to move some collision objects as well.

Issue:
The player can trap the rigid-body objects between a mover and wall collision; this eventually allows the player to push the spherical object through one of the two pieces of collision.

Question:
Is there anyway to detect the state of being crushed so I can handle this special case?

No one has ever had to test for a Rigidbody being stuck between two pieces of collision?

Well, several things come to mind. Never had to do such a thing but have thought about it while sitting on the toilet or driving :smile:

One thing is that you can use the OnCollisionStay function.

You would tag the crushers with some tag (say “crusher”) And then in OnCollisionStay you would check if the object collides with more than one crusher

var crushers : int = 0;
function Update(){
crushers = 0;
}

function OnCollisionStay(col : Collision){
if(collision.transform.tag == "crusher"){
crushers ++;
}

if(crushers > 1){
//kill
}
}

Another way would be to use raycasts. You can also use raycasts in conjunction with the OnCollisionStay.
You can also check the angle between the two crushers to determine if they are facing each other and can crush the object.

Hope that gives you some ideas.

How complex do you need your crushes to be? The simplest method is probably to check for collisionStay then do a raycast to check the depth of penetration, if you get a few of these in a row with enough penetration you are being crushed. I did this with some success in PhRONIX.

If you want a more physically realistic crush you need to manually work out how much force is being applied to the crushed object and what direction.

Excellent ideas from both of you. Looking at it now.

(I know that this is an old post, but every time is good to answer)

I tried out this:
My crushers has the ‘Walls’ tag. There is a little spherical heart appended to my sphere. When a ‘Walls’-tagged object touches that little heart, the sphere disappears. Dark-Protocols’ way seems better, but I have to try it out.