2
\$\begingroup\$

I have an animation of a character climbing with root motion in it (i.e. the character moves generally upwards for a couple of units during the animation). It is intended as a one shot, not a loop. The skeleton is fairly standard hips > spine 1, hips > right leg, hips > left leg etc. The root is the hips and the pivot is between the soles of the feet.

I know its generally best to make in-place animations without root motion but scripting the upward movement using Vector3.Lerp etc looks unrealistic (in reality when rock climbing for example the upward motion will come in perdiodic bursts as the knees are first bent, then extended, rather than a constant movement upwards), so I want to keep the root motion in the animation.

Problem is when the animation has finished Unity still considers the transform pivot to be in its original location, before the skeleton climbed up two units. Is there any way to instruct Unity that the new transform position is where the characters feet have ended up after the animation has finished?

I figure I could parent the hips to an empty which moves the charaters around normally, detatch the empty before the root motion climb, move it by the same amount the hips moved then re-attach but is there a less hacky way? Some kind of transform.returnToOriginalOffset method perhaps?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

UPDATE

You are right my original explanation is a bit too light in details. In details, in the root motion the Body Transform and Orientation are stored in the Animation Clip, so when the animation ends you can write a piece of code that gets the new info and translate the transform position to your desired location, just make sure you take in consideration the offset, might move it to the center of the character, if that happens easy fix, you can calculate that as well and move it.

some more info can be found in this link

https://docs.unity3d.com/Manual/ScriptingRootMotion.html

\$\endgroup\$
6
  • \$\begingroup\$ Can you be more specific? Do you mean in the animation itself? \$\endgroup\$
    – user87997
    Commented Sep 4, 2019 at 5:33
  • 1
    \$\begingroup\$ @Absinthe meant was to store it in variable mostly Vector3 via script not in the animation \$\endgroup\$ Commented Sep 4, 2019 at 12:47
  • \$\begingroup\$ @DigvijaysinhGohil Thanks but I don't see the point of that. I want to update the transform to the new position of the mesh, not move the mesh back to its original position. If I've misunderstood can you explain in more detail? If you mean script the motion rather than animate it thats exactly what I'm trying to avoid as it will never look as good as an animation. \$\endgroup\$
    – user87997
    Commented Sep 4, 2019 at 13:06
  • \$\begingroup\$ Firstly, could you tell me if that "Apply Root Motion" checkbox is selected in your characters Animator component? \$\endgroup\$ Commented Sep 4, 2019 at 13:12
  • 2
    \$\begingroup\$ @DigvijaysinhGohil I just realised what that tick box is for! So, I've solved it by enabling it when starting a root motion anim and disabling it for other anims. \$\endgroup\$
    – user87997
    Commented Sep 4, 2019 at 17:17

You must log in to answer this question.