How to check if a rigidbody is being crushed

I’m trying to implement a Thwomp - like enemy for my game. Both enemy and my player are rigidbodies. But I don’t know how to check if certain rigidbody is being crushed. Player can’t take damage on a mere collision, only when he’s being crushed (either through the floor or sideways or really from any direction). But I don’t know how to check for that. Anyone got any ideas?

Perhaps use this

Use it once between the ‘Thwomp’ and the player and once between the Player and the floor and resolve.

Sorry if this is a load of crap but I was just entertaining the idea:

#pragma strict
public class BeingCrushed extends MonoBehaviour
{

	var myStayCollision : ConstantContactCrush;
	function Start ()
	{
		myStayCollision = GetComponent(ConstantContactCrush);
	}

	function Update ()
	{
		if(Input.GetKeyDown(KeyCode.O))
		{
			OnCollisionEnter(lastCol);
		}
	}
	var lastCol : Collision;
	function OnCollisionEnter(col : Collision)
	{
		if(col.gameObject.name != "Terrain")
		{
			lastCol = col;
			myStayCollision.enabled = true;
			Debug.Log(col.impulse + "  " + col.gameObject.name);
			StartCoroutine("yieldResolve", col.impulse);
		}
	}

	function yieldResolve(colVec:Vector3)
	{
		yield;
		yield;
		var resolved : Vector3 = colVec + myStayCollision.impulseVector;
		Debug.Log("Resolved " + resolved);
	}
}

#pragma strict

public class ConstantContactCrush extends MonoBehaviour
{
	public var fireOnce : boolean = false;
	public var impulseVector : Vector3;
	function OnCollisionStay(col:Collision)
	{
		if(!fireOnce)
		{
			impulseVector = col.impulse;
			Debug.Log(col.impulse + "  " + col.gameObject.name);
			fireOnce = true;
		}
		enabled = false;
	}
	
	function OnEnable()
	{
		fireOnce = false;
	}
	function OnDisable()
	{
		fireOnce = false;
	}
}

In essence, what I was playing with here is the idea of resolving the impulse of the fresh collision with the impulse of the Stay’d continuous collision with the ground (I was hashing it out so theres probably something broken with it). I wanted OnCollisionStay to only be fired for one go as its expensive routine, being fired every frame, so I separated it to another class and enabled it as needed passing the information to the BeingCrushed class.

Its a very crude concept example, but there’s an idea in there somewhere.

Do you want to check the collision between game objects or you want to see which one has a Rigidbody ?
For checking if an object has a Rigidbody:

If(gameObject.GetComponent() != null)
{

}

I thought about this way too hard, and then realized a simple solution:

For my fps game, I put a collider inside of the player collider, which instantly kills the player if it touches anything. It will only come in contact with another collider if a collider is clipping inside of the player - which is the same as being crushed. It has a script with this:

private void OnCollisionEnter(Collision c) {
        print("player got crushed");
        Die();
}

Just make sure it has a frozen rigidbody and can’t collide with the player collider.