- Home /
Character Bone structure and adding weapon to hand
I'm not sure if this is a unity bug, I'm doing something wrong, or if I am doing this the completely wrong way.
My goal is to have a character (using mechanim for animation) with a standard bone structure. This far is easy, and I have all the animations working. I now am working on my weapon system - the player should be able to 'hold' a weapon in his hand. I first thought to use a script that takes the Hand bone, and takes the object I want to hold (a gun, knife, cup of tea etc.) and simply do something like the below:
cupoftea.position = hand.position;
supoftea.rotation = hand.rotation;
This isn't perfect, as the position and the rotation would need to be offset - but the bigger problem was the delay - when the player brings his arms up to aim, the gun sort of lagged behind - not ideal.
The better way to do this, would be to use simple GameObject parenting, as this seems to be far more efficient than using a script and generally works better.
My character has a bone called Spine2. When the bone is selected, it is in the correct place (in the center of his chest). (sorry, can only upload two images - take my word, without the gun, the bones are all fine)
So, I add a gun (just a simple model of an M9 to test) to the hand bone, and relatively align it so it looks right (this could be done very simply for each weapon in code when changing weapons).
Now the weird part that is throwing me off - when the gun is added, the spine2 bone (along with several others) move out of alignment, and most of them seem to move to the gun's location.
I have noticed something after writing this, in the editor, if I change to pivot mode, the bones look correct, it seems to just be the center mode they are wrong.
So, my question(s) are:
Can I just leave the bones like this? For now, it seems to work okay, but I'm not convinced that is right.
Im I doing this the correct way? Is there a better way for a character to hold a weapon?
I have this problem too- again when putting guns in hands, except that it stays wrong in pivot mode. I don't know how to solve it, but it means it's not just you with the problem. Also, the model I am using has worked before without a problem so it is not the model's fault.
It might just be a visual bug, as the rotation and position of the bone seems to work okay.
Your answer
Follow this Question
Related Questions
How to use AvatarBuilder.BuildGenericAvatar() ? 0 Answers
I can preview the animation but in scene it doesn't work 0 Answers
Is there no way to create Avatar and AvatarMask for Transform trees? 0 Answers
Removing Bone From Hierarchy Animation/Bone Rotation During Animation Problem[Humanoid] 0 Answers
Adjust/Change AvatarMask at runtime? 0 Answers