4
\$\begingroup\$

I have an animation created with the built-in dope sheet. It plays correctly but I would like it to be played relative to current object transformation. For example I have a palm tree that moves its leaves. If I rotate the palmtree and then start the animation leaves does not play animation relative to its new position/orientation. I know it is playing this way because of the animation being absolute. Is there any way to make it realtive to current transformation?.

Thanks in advance.

\$\endgroup\$
8
\$\begingroup\$

The only way to do this is to make an empty gameobject and then put the object you wish to animate inside it, then putting an animator on the new parent.

For example, here you would put the tree and leaves in a parent object, and transform the parent object as needed while the animation plays relative to the parent.

\$\endgroup\$
  • \$\begingroup\$ Thant worked. Just had to made the palmtree child of a parent and apply the transform in the parent. \$\endgroup\$ – Notbad Apr 9 '14 at 11:19
7
\$\begingroup\$

Another way to handle this, which works well if your objects don't move, is to save the position of the object before you start the animation.

Like so:

        startPosition = transform.localPosition;
        animation.Play("testAnim");

Then during LateUpdate, you jus add that position on top of the position of your object, which effectively shifts it by it's original position. Since htis happens in LateUpdate it happens AFTER the animation offset was applied, maintaining the animation.

Like this:

void LateUpdate() {
    transform.localPosition += startPosition;
}

Since this offset is static this only works with non-moving objects. Of course you could modify this startPosition to move the object but it get's a bit more roundabout then.

Hope this helps :)

\$\endgroup\$
2
\$\begingroup\$

You can also :

  • On the animator of the object you want to animate check "Apply root Motion"

  • in the inspector of the animation, click "Generate Root motion Curves"

Et voilà :)

\$\endgroup\$
  • 3
    \$\begingroup\$ would you mind to expand a bit your answer a bit more? What is this Apply root motion used for? And what about the root motion curves? I have been reading the doc and I can't get it. Please it would be nice if you could use just plain language. \$\endgroup\$ – Notbad Nov 23 '15 at 0:39

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.