- Home /
OnTriggerEnter not firing if rigidbody is on its side
Hi,
I have an explosion that is modeled as a sphere collider (IsTrigger checked) and a rigidbody with a box collider as my target entity. OnTriggerEnter works fine, until the object is resting in a rotation with Z != 0 (i.e. upside down, or on its side). If I rotate the object back normally OnTriggerEnter works perfectly again.
My explosion's OnTriggerEnter looks as follows:
void OnTriggerEnter (Collider collider)
{
CreepLogic creep = collider.GetComponent("CreepLogic") as CreepLogic;
print (collider);
if (creep != null)
{
collider.rigidbody.AddExplosionForce(500,this.transform.position,10);
creep.Damage(Damage);
}
}
In fact the rigidbody stops moving completely when it reaches certain rotations - so it might be something else?
I'm new to unity, so besides the main issue of OnTriggerEnter not working, I have two more quick questions: is using GetComponent followed by a null check the correct/best way to check if my colliding entity is a creep? Also, I only want to explosion to exist for one frame. I've done this by putting Destroy(this,0.1f) in the Explosion's update function. Is there a better way? The explosion has particle effects etc components too.
(I know I should be using ForceMode.Impulse - will go change that)