Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
Thant worked. Just had to made the palmtree child of a parent and apply the transform in the parent. –  Notbad Apr 9 at 11:19
add comment

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 :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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