- Home /
How to play one animation using animator on different positions?
Hello everybody,
I have a problem. I created an animation on a gameobject RedApple. Then I added a component animator to the RedApple and linked the animation using SetBool when triggered. Then I added a GreenApple to the scene to a different possition, added an Animator component and linked the same animation. The result I want is to play one animation on different positions. What I get is same animation on one position where the animation was created even when two different gameobjects have different positions... How should I solve it?
Thanks a lot.
Answer by GiyomuGames · Jul 18, 2015 at 12:10 PM
Edit: I put one of my comments as an answer:
You need to recreate your animation.
Create one empty object called RedAppleParent
Under this object put your RedApple sprite or 3D model (the object that was initially your main object)
Don't forget to put RedApple position at (0, 0, 0)
Create your animation on RedApple. You can modify x, y and z for your animation.
That's it! Prefabify RedAppleParent so you can put many of them in your game
If you want GreenApple:
Start from a RedAppleParent
In the GameObject menu chose > Break prefab instance
Rename your object to GreenAppleParent
Inside the GreenAppleParent rename RedApple to GreenApple and modify its sprite
That's it! Prefabify GreenAppleParent so you can put many of them in your game
Initial answer: When you recorded your animation you probably recorded the transform position at the same time. Therefore the animation forces the object to be at a certain position. Remove the transform keys (x, y, z) from your animation and you should have better results.
Hey, thanks for your reply. That is true. But I want to animate the gameobject moving on it's Y axes. When the player collects the gameobject I want the gameobject to jump up and down and then dissapear. I use position and scale in my animation. When I remove the X axis, my animation is broken...
I read something about placing the animated object into parent gameobject. Is it my case? How shoud I exactly do it?
That is correct. Put your object under a parent so your animation only modifies the y (and/or x) of your object relatively to the parent. As you result you can put your parent object wherever you want and it will work.
I don't understand. I have about 50 objects to be animated. Should I put them all under a parent object? Do I have to create the animation from the beggining? And where should I place the animater - to the parent gameobject or to my 50 objects that will to be animated?
Sorry let me re-explain. You need to recreate your animation indeed.
Create one empty object called RedAppleParent
Under this object put your RedApple sprite or 3D model (the object that was initially your main object)
Don't forget to put RedApple position at (0, 0, 0)
Create your animation on RedApple. You can modify x, y and z for your animation.
That's it! Prefabify RedAppleParent so you can put many of them in your game
If you want GreenApple:
Start from a RedAppleParent
In the GameObject menu chose > Break prefab instance
Rename your object to GreenAppleParent
Inside the GreenAppleParent rename RedApple to GreenApple and modify its sprite
That's it! Prefabify GreenAppleParent so you can put many of them in your game
Your answer
