1
\$\begingroup\$

I'm using blender to model, rig and animate my character for a Unity game, but there is something that I can't figure out by myself neither find on the internet, for example:

Lets say the main character is able to punch npcs and I want that punch aimed to the face but not all npcs have the same height.

How can the animation be adjusted to handle this?

Inverse kinematics seems to be the solution but to this date I couldn't find any good example or information about this subject better than "Check this box to fix the animation for stairs" and so on.

\$\endgroup\$
  • \$\begingroup\$ If you can move your character's parts relative to each other, one way to handle this would be to put an invisible part inside your model and have your character punch that instead. When a character with a different height comes into your character's range, move that invisible part and he should still punch that instead of having the same animation. (Not sure how you'd go about it though) \$\endgroup\$ – John Hamilton May 4 '17 at 10:33
1
\$\begingroup\$

The only way I could think that will go well is to have the "joint"(I will call it joint1) that your arms are attached to and have it "lookAt"(in a script attached to it that says for it, in update, to use transform.LookAt) at an invisible object on the closes npc's head, OR if that don't work right, try having the joint1 calculate the height of the npc's head compared to the player's fist height and have the joint1 rotate accordingly and stop based with a raycast it has pointing foreward(I a not at my computer therefore I can't show code right now, but info on this can be found in the scripting API)

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Make one animation for the lowest punch and one animation for the highest punch that you need. You can create multiple layers in the Animatior Controller in Unity and fade inbetween those layers. If the lowest animation is 1 meter and the highest animation is 2 meters you can crossfade between the layers. Set Layer Weight to 60% to punch someone at 1.60 metres.

Here's something I did for a boat:

enter image description here

Access the Animator and call

punchAnimator.SetLayerWeight(layerIndex, (targetpunch - lowpunch) / (highpunch - lowpunch);

Where targetpunch, lowpunch and highpunch are values for the height of the punch. I hope this helps you punch people with greater accuracy.

| improve this answer | |
\$\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.