- Home /
Compound collider fires events for each child collider per enter/re-enter the trigger! Is there a reliable way to make it fire only once per compound collider per trigger enter?
My gameobject is a parent with a rigidbody and children containing colliders. This Object (compound collider) should trigger only once per entering/re-entering the trigger. The standard behaviour on this is that for each child collider in the compound collider a trigger event is fired, actually this makes sense. But, is there any smart way to limit it to the compound collider firing only once per entering/re-entering the trigger and not for each child? In my situation it would be nice to have it fire only once per trigger enter.
Currently I have this code running, it improves the situation but it is not reliable enough:
private var collisionTimeDelta : float = .2; private var collisionTime : float = 0;
function OnTriggerEnter (collider : Collider) { if (Time.time > collisionTime) { collisionTime = Time.time + collisionTimeDelta; if(collider.gameObject.tag == "myCollider") {
DoSomething();
} } }
Answer by klay · Sep 07, 2012 at 08:32 PM
I'm imagining this scenario being needed for something like a healing area trigger--where you want your object to get the "Heal Thyself!" message only once, and not once for each collider, when the game object passes through the healing area.
What I would try is designating one collider as the one which acts on the healing message, letting the others ignore it. Or you could add a distinct healing collider to the center of your object so that when it (the healing collider) passes through your healing area trigger, it fires.