- Home /
Pick up toy and attach to hand
Hello,
I have a character with the animation "walk" that picks objects up through trigger. I have no problem doing that - I simply make the object a child of the character. What I would like to do is to attach the object to the character's hand (moving with the hand as the character walks). The model of my character has many children one of which is called "Hands". The code attached to the object is:
if((myTrigger.gameObject.tag == "PlayerB")
{
hand=myTrigger.transform.Find("Hands");
gameObject.rigidbody.isKinematic = true;
gameObject.transform.position = hand.transform.position;
gameObject.transform.parent = hand.transform;
}
Unfortunately the object is attached to the character "in general". It has the same position as when I replace "Hands" with "Face" which shows me it doesn't take into consideration the part of the body to which it should be attached. Could someone give me an advice?
Thanks in advance.
Answer by Unamine · May 30, 2011 at 10:48 AM
Well, I think this is happening because of this line of code:
gameObject.transform.position = hand.transform.position;
You're taking the general position of the object by repositioning it inappropriate, try creating a new gameObject and call him or anything handPickup and relatives it and place it by the view hierarchy with the character's hand
By doing so, change the code to:
handPickup.transform.position = hand.transform.position;
I hope I have Helped ...
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Detach child and add force 0 Answers
what happens when Unit in Hierarchy is destroyed? 1 Answer
How do you select a root object from a child's script? 1 Answer