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!