- Home /
Constantly checking OnCollisionStay
This does not work unless the rigidbody is actively moving. It is like it is not tested contantly. How can that be done - and how should i fix the problem?
void OnCollisionStay (Collision collision)
{
if(collision.rigidbody.mass > 3f)
Destroy (gameObject);
}
Answer by VIPINSIRWANI · May 07, 2014 at 01:36 PM
Hi Once try with this code
void OnCollisionStay(Collision clsn)
{
Debug.Log("Clsn"+ this.gameObject);
if(this.gameObject.rigidbody.mass > 0.9f)
Destroy(this.gameObject);
}
Answer by Loius · May 07, 2014 at 05:09 PM
You might try setting the rigidbody to Continuous ... whatever option that is. There's a dropdown.
You might also try OnCollisionEnter. Since you're destroying (and that can only happen once per object), it should have the same effect.
You probably also want to be sure there's a rigidbody on the object with this script attached.
I think I need to use OnCollisionStay since the point is it should check a stationary rigidbody. I dont understand why I would attach a rigidbody to the object with the script? It is the mass of the rigidbody that we collide with that is checked :)