- Home /
Parent weapon to hand bone
Hi,
I know this question was made before but the solutions I found did not work as espected.
I parented a gun object to the character´s hand bone using this code:
gun.transform.parent = rightHand;
gun.transform.localPosition = Vector3.zero;
gun.transform.localRotation = Quaternion.Identity;
I tried this with an empty acting as a child of right hand bone or a direct parenting to right hand bone.
After that, the gun started to follow the character but not in the right position and rotation but some units away from hand (floating in the air).
I don´t know what is wrong with the code or what I am missing.
As you can see in the picture, the gun is away from right hand but if character is moving, the gun follows the right hand.
Answer by FreeTimeDev · Feb 13, 2014 at 05:36 PM
Your modifying the localposition after its been parented. Set the transform.position to the same as the hand, then parent it.
Thanks for your help but it did not work. It only works with simple objects without rigidbody, animator,...
Answer by douglasquade · Feb 17, 2014 at 03:24 PM
Your solution works with the Constructor model that is included in Unity as ThirdPersonController but it does not work with my own models.