- Home /
trigger enter not registering with child
Hello,
I have a target object with the On Trigger Enter (other : Collider) function{
. The trigger object is an arrow made of 2 parts, parent and child. if i have the trigger collider on the parent it works like a charm, but i would like the collider to be on the child which doesn't seem to trigger anything. any ideas why the collider will only work for the parent(yes i check the isTrigger box on both, Thanks
Answer by ThumbStorm · Apr 22, 2010 at 04:18 AM
I found there was a rigidbody on the parent and the child. So i took the one off the child and it works. That was a fun 3 hour headache!
Answer by e-bonneville · Apr 22, 2010 at 02:45 AM
Hmm. I don't know, but I got some nice effects by following this answer to my question. It's kind of finicky, but what I ended up doing was (using triggers like you) was creating a couple of triggers for the terrain. Each trigger checked what colliders entered it. If the collider was an arrow, it told it to do a function which froze the arrow by setting the drag up high. I'll post the related scripts:
Script for the arrow:
var hit = false;
function OnCollision () { rigidbody.drag = 3000; rigidbody.angularDrag = 3000; hit = true; Kill(); }
function Kill () { yield WaitForSeconds(5);
Destroy (gameObject); }
function Start () { Timeout(); }
function Timeout () { yield WaitForSeconds (2); Kill(); }
Script to put on the terrain collider/triggers:
function OnTriggerEnter (other : Collider) {
if (other.gameObject.CompareTag ("Projectile")) {
other.SendMessageUpwards ("OnCollision");
}
}
Make two separate gameObjects, an arrowhead and an arrow-shaft. Then make the head a child of the shaft. Next, add a fixed joint to the arrow-shaft, and make it connected to the arrow head. Add colliders and rigidbodies to both objects. Then change the drag on either, making sure that the shaft has more drag, causing it to fall slower than the head. Finally, add the arrow script to the shaft, and the terrain script to the terrain colliders, which should be on empty gameObjects aligned with whatever you want the arrow to stop on. That should be it.
P.S. Is this answer overkill or what?
I'm too far along into this to change my set up on the arrow. I have a model of an arrow linked to an empty game object which has gravity and then i animated the arrow's rotation. The good thing is that you'll never see the arrow hit the ground or have to stick into anything. Next time i'll try you way, it seems better. Thanks for the info!
Took a break and tried your way of creating the arrow and it's pretty sweet!