- Home /
Inconsistent behaviour in child triggers
Hi, please help!
In my game I have some water with a large box collider and isTrigger set true to represent the sea.
I also have a game object, a helicopter, which has a rigidbody. It has several layers of child objects for various functions. It has a number of colliders and compound colliders in its child objects. The top object with the rigidbody has a script containing OnCollisionEnter to handle physical impacts in any of the colliders and an OntriggerEnter function to handle if the helicopter touches the sea. The physics works fine and the sea trigger also works fine.
Here is where it gets inconsistent:
One of the child objects is a radar which uses a sphere collider with isTriggger set true to monitor the nearby AI helicopters. I have an OnTriggerEnter function in the script attached to the radar object and this works fine. And when the radar sphere trigger hits the sea trigger the radar's OnTriggerEnter runs and handles the event, which is what I want - I don't want my helicopter's top level OntriggerEnter function to run, which causes the helicopter to crash and sink, just because the radar 'field' hit the sea.
But, another child object has a capsule collider for another purpose. It too has isTrigger set true and also has a script attached with an OnTriggerEnter function. When this trigger hits the sea, this 'local' OnTriggerEnter function doesn't run and the event instead passes up to the top level helicopter OnTriggerEnter function which causes it to crash and sink. I know there isn't a problem with the 'local' one since it does run when the trigger hits the terrain.
In effect, these two child objects are structured the same but appear to behave differently. I can fix the offending child by attaching a kinematic rigidbody to it but I don't really see why this is needed for one but not the other. Also, I appear to incur quite a performance hit with this extra rigid body attached.
Any help would be greatly appreciated.
Also, is there a general rule to follow when you need to mix colliders and triggers within an object hierrachy in terms of where you put them and where the trigger/collider functions should go? I thought I was doing alright until this happened!
I am working on a flying game at the moment. I have child gamobject with collider attached to my plane (isTrigger is turn off on the child so that i can use OnCollisionEnter).
The problem arise when my plane has rigidbody and child collision will affect it (Compound collision). I wanted the child to have non-trigger collision and yet not to affect the rigidbody of my plane.
The only solution I have so far is to unparent the child. Write a script to tell the child to follow the parent.
Answer by travellinguncle · Oct 06, 2014 at 07:16 PM
OK, I'm back on Unity after a long break. Just answering my own question for the sake of anyone who might stumble upon my question. I've now updated to Unity 4 and without making any changes to the project the inconsistency is gone. Both child objects that contain triggers have to have kinematic rigidbodies to work correctly. After reading further on rigidbodies and colliders and triggers this makes sense to me. It seems there was some sort of inconsistency in the Unity engine that has now been removed.