- Home /
Animation does not play in relative position, even with parenting
I created a simple bounce animation using Unity's animation editor. I learned that you have to create an empty game object as a container/parent if you want the animation to play at the current position of the object, so I did and put the player object inside this empty game object. Then I created the animation on the player object itself.
A script, also on the player object (not the empty game object!), triggers the animation when you reach a certain coordinate.
To my frustration, when I play the animation, it plays it at the original coordinates of the player object, and NOT at the location it currently is at.
Have I forgot something else? Am I missing something?
To recap: I have an empty game object as a parent. The animation (and scripts, rigid body, collider, etc...) are all located on the player object INSIDE the empty game object.
Help would be much appreciated. Thanks.
Sure. Below you'll find a screenshot of how I setup the game object:
http://www.emptyhouse.net/fileshuttle/snapshot_1dec.jpg
The code is a simple currentTransform.animation.Play("BounceTest");, and works fine, except the game object plays it at the default 0,0,0 location, ins$$anonymous$$d of the current location.
Answer by Erwin_Br · Jan 27, 2011 at 09:45 PM
Okay, after struggling for another day I seem to have found the solution.
The solution is that I need to animate the empty PARENT object, the container, and NOT the game object inside it! Since my script is still attached to the object inside the empty parent, I need to call the animation on the parent like this:
currentTransform.parent.animation.Play("BounceTest4");
I don't think I have ever seen this in a tutorial, but apparently it works. I wish the documentation would be more clear about this, because the bald patch on my head is definitely growing.
I don't understand with this section. I also have with this problem.
when i type in currentTransform i get a compiler error saying unknown identifier 'currentTransform.'
Answer by DaveA · Jan 27, 2011 at 01:40 AM
I'm guessing: The original animation was in world space. When you parented it, it offset that to appear in the same place, offset from the parent. Check the values on your animation curve(s) they may be quite different from what you originally authored.
I was pretty sure the animation was created in local space. To be sure, I created a new one in local space. It still plays at the original location. Another screenshot, showing the animation: http://www.emptyhouse.net/fileshuttle/snapshot02_8b03.jpg
Answer by Bomadeno · Aug 29, 2012 at 02:03 PM
In addition to the previous answers, make sure root transform has no animation curves. If it does, it will play in world space.
Answer by gringofxs · Jul 13, 2013 at 04:25 PM
do you have the complete script sentence.
currentTransform.parent.animation.Play("BounceTest4");
I have the same problem. I want a turret's barrel to recoil when shot however if the turret aims up, ins$$anonymous$$d of recoiling back into the base of the turret (as expected) the barrel slides on the world Z axis ins$$anonymous$$d of local z axis and results in a retarded turret. Tried putting that animation component on all objects above and including the barrel and the result is the same.
Answer by jveronda · Mar 03, 2014 at 04:59 AM
im having the same problem with just getting an enemy to have a walking animation when it comes towards me. any help??
Your answer

Follow this Question
Related Questions
Use Parent to fix the rotation of character 1 Answer
Making an animated door, that will be reused over a level, need to reference its parent 2 Answers
what to do the parents animation doesnt play on child gameobject in unity 5.6? 1 Answer
Attaching First Person Controller to Kinematic Rigidbody 1 Answer
RE: Archer FPS script 1 Answer