- Home /
Attaching Object as child at certain point in animation
Hi Gang,
I have an archer that is reaching back to withdraw and arrow from his quiver and shoot it. I am instantiating the arrow in the quiver. During his animation when he reaches back to draw the arrow I wish to attach it to his hand and then as he shoots the arrow launch it as a projectile. I can easily instantiate the object as a child of the hand but I wish to time it with the animation drawing the arrow from the quiver.
Is there a way to attach an object as a child to a parent at a certain point of my choice during the animation?
Thanks, The Oz
Answer by AprendaGames · Feb 12, 2012 at 11:23 PM
Use an animation event: http://unity3d.com/support/documentation/Components/animeditor-AnimationEvents.html
Thanks after I set the animation event at the appropriate location I created a function to Transform.find the parent (hand) and attached the arrow object as a child to it.
Thanks again.
Answer by TheOz · Feb 14, 2012 at 02:13 AM
Thanks That got me on the right track. After creating an event where I wanted to attach the arrow to the hand I created a function in the script on the character and did the following:
function drawArrow() {
rightHand = transform.Find("Pelvis/Spine1/Spine2/Spine3/Spine4/Ribcage/RCollarbone/RUpperarm/RForearm/RPalm");
arrow = GameObject.Find("Arrow(Clone)");
Debug.Log("found :"+arrow);
Debug.Log("found :"+rightHand);
arrow.transform.parent = rightHand.transform; // this should attach the arrow to the right hand of the archer
transform.localPosition = Vector3(0,0,0);
rigidbody.isKinematic = true;
One thing I found was that you had to drill down the characters bone structure with transform.Find to get the right parent before attaching.
The Oz.
Your answer
Follow this Question
Related Questions
How do instantiate stuff as a child 4 Answers
Smart way to add border to a text mesh in a 2d environment 1 Answer
VUFORIA: Playing an animation for a instanced model? 2 Answers
Destroy the child instantiated object 1 Answer
Instantiating multiple prefabs with animations all appear at 0,0,0 3 Answers