0
\$\begingroup\$

I have this object which is being animated, the animation moves a arm and hand. I want it to look like it's holding something but I can't move the object to the hand because even though the animation appears to move the world position of the animation object stays the same, the objects parent is the hand but it's still not moving to it. So how do I move the object to the animations hand while it's being animated in unity?

Maybe this could help to visualize what my problem is:

enter image description here

enter image description here

I found another way around the problem: attached the object as a child of the bone instead of the hand mesh. I still don't know why it didn't move with the hand.

\$\endgroup\$
1
\$\begingroup\$

In order for it to work you have to parent the bat to the bone and not to the hand. In that way it will move with it and follow all the animations of the bone.

\$\endgroup\$
0
\$\begingroup\$

If your problem is that the model is animated but the object is not, then you have to make the object a child of the arm, so that when the arm moves, the position and rotation of that object depends on the transform of the arm.

\$\endgroup\$
  • \$\begingroup\$ And maybe unity considers your model as a single object, that's why you don't see the object moving \$\endgroup\$ – user51054 Jul 17 '15 at 7:57
  • \$\begingroup\$ It is a child of the arm. \$\endgroup\$ – Awesome Name Jul 17 '15 at 8:06
  • \$\begingroup\$ Okay... So i don't have enough unity knowledge to answer your question :/ \$\endgroup\$ – user51054 Jul 17 '15 at 8:14
  • \$\begingroup\$ I figured out the problem... well actually i didn't, but i managed to found another way around the problem. I still don't know why it didn't move with the hand. Well anyway the solution was: i attached the object as a child of the bone instead of the hand mesh. \$\endgroup\$ – Awesome Name Jul 17 '15 at 8:37
  • 1
    \$\begingroup\$ Yeah, that's the "right way" to do it. \$\endgroup\$ – jzx Jul 17 '15 at 9:16
0
\$\begingroup\$

It's very difficult to move an object independently to match an animation. The standard method is to attach the object to the skeleton of the mesh.

Otherwise, you would need know the precise dimensions of both meshes (character/hand and object) and the movements of the animation at every frame if you want it to look right, which can be pretty resource heavy.

Alternately you would need to do some rather complex computations based on the key-frames of the animation and you would still need to know the precise dimensions of the mesh. You don't want to have to rely on 'magic numbers' like mesh dimension or else when you change the mesh, you need to change your code too and that is bad practice in programming. This is also rather computationally expensive for little gain, especially if you are trying to get the dimensions of the mesh on the fly.

The animator handles all of this complexity for you if you attach your object to the skeleton. Though not perfect, it will almost always be good enough. Your attached object may still penetrate the mesh at some points, since the animator doesn't track the dimensions of the mesh either, just the skeleton.

You might get more accuracy if you animate the object separately from the character mesh so you can make slight adjustments in your object animation to account for variances in how the object should move compared to the hand, but that is usually overkill and that kind of accuracy is rarely needed in a game.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.