Making a gameObject a child of another via script problem

in my game i have a ninja who needs to draw his sword. I have an animation that the ninja reaches up to take the sword of his back. (this is attached to a trigger around the handle of the sword that the hand goes threw)

var sword : Transform;
var arm : Transform;

function OnTriggerEnter (hit : Collider) 
{
        if(hit.CompareTag("attack arm"))
        {
            sword.transform.parent = arm.transform;
        }
}

but when i play the game and the ninja reaches up nothing happens. i don't get any errors but it still doesn't work. Any ideas?

1 Answer

1

A couple ideas:

  1. Make sure the tag is exactly "attack arm". and that your sword is tagged appropriately.

  2. sword.transform is redundant as well as arm.transform. You declared that they are transforms above.

  3. Make sure you also a collider or trigger attached to your hand. The hand also has to have a kinematic rigidbody attached or trigger messages won't be sent.

My guess is that the 3rd solution is correct.

At this point you should have a trigger on the hand and the hilt of the sword. You need to put a kinematic rigidbody on the hand. According to the collision matrix in the reference manual, a static trigger will send a message to a kinematic trigger.