# Animating a sprite with mecanim

I want to try animating sprites with the Unity's mecanim. All the tutorials I found used bipedal humanoids, which already have the avatar for the animator component and imported animations.

What I want, is to create animations inside Unity(like in legacy) and use the animation state machine. So the question is: How do you animate a single sprite using a mecanim's animation state machine?

• Pretty broad question. What, specifically, are you having trouble with? What have you tried that didn't work? – MichaelHouse Feb 27 '14 at 15:25
• @Byte56 What is unclear? I mentioned in the question that I wanted to use legacy type of animations with mecanim. To which I found no tutorials which means I had no idea what to try. – Esa Feb 27 '14 at 16:04

Got the animation working with the new mecanim system. Something to note is that Unity does not allow physics and animations on a GameObject at the same time.

You can create legacy type animations for an object following these steps:

1. Create a new animation controller
2. Create a new animation
3. Add Animator component to the object
4. Open the object in the animation window with the object selected
5. Click Add Curve and select Transform/Rotation
6. Set the second keyframe y-axis rotation to 180
7. Press play to see the animation

These animations can then be added to the animation state tree.

• What do you mean that Unity doesn't allow physics and animations on a GameObject at the same time? This seems false as I have physics affecting animated objects in a platformer. – XNargaHuntress Feb 27 '14 at 16:16
• @XGundam05 If you put a rigidbody with gravity on a GO it will fall. If you put an animator with an animation to it, it does not fall anymore. You have to add the physics to a parent object to allow both. Link: answers.unity3d.com/questions/337817/… If you put the set the object to a kinematicRigidbody then you can have animations but the physics effects no longer affect it. Link: docs.unity3d.com/Documentation/ScriptReference/… – Esa Feb 28 '14 at 6:38
• @Esa I am thankful for the legacy part of your answer. I was not knowing about that and it became quite a handy to me! – Vivek Kalkur Feb 28 '14 at 7:28
• If you want to animate with physics you uncheck the "apply root motion" box and check the "animate physics" box... Is that what you are talking about? – Savlon Feb 28 '14 at 11:03