Animation Speed in Unity3D

The new Animator component in Unity can post a few problems when dealing with animation speed. I will present here three methods in which you can control it.

By default animation speed is set to 1 and that means it will play with the speed the artist intended it. However you can change that factor. You can set it to 2 in order to play twice as fast or to 0.5 to play twice as slow. You can either set it to a negative number in order to have it play backwards.

1. Set speed in animation state

Select an animation state in the animator window and up in the Inspector you should see this

Animator inspector

You can set the speed in the speed box as explained above

2. Use the Animator component in code

You can obtain the animator component in code by calling GetComponentInChildren<Animator>() method. Then you can change the speed by changing the value of Animator.speed property. You can do so dynamically if you need to change speed on the fly from code or want to pause speed in order to freeze the animation.

Unfortunately using this method has a side effect in case you have more than one animation for this particular object as it governs the animation speeds for all playing animations for this object. Because of this issues, this should be used with care and is suitable for objects with one animation playing at a time.

 3. Use a blending tree

Right click an animation state and select “Create New Blend Tree in State” like in this image

Screen Shot 2013-11-07 at 22.17.02

Double click the state to enter it. In the lower left corner click the “+” sign on parameters and add a Float parameter which will control the animation speed

Screen Shot 2013-11-07 at 22.17.47

You can see that the parameter is automatically selected as the blending tree parameter

Screen Shot 2013-11-07 at 22.17.51

Click the “+” button in inspector and add click the “Add Motion Field” option and add the animation in question. Do this again and add the same animation.

Screen Shot 2013-11-07 at 22.18.13

 

Screen Shot 2013-11-07 at 22.18.44

Uncheck the Automate Thresholds option

Screen Shot 2013-11-07 at 22.19.03

Set at which threshold the animation should start and for which speed in the box to the right

Screen Shot 2013-11-07 at 22.29.45

There we go, the three animation speed changing ways I’ve learned so far in the new Unity’s Animator component, hope you find them useful.

Please share any other ways you know of accomplishing this task.

Cheers!

This entry was posted in Jungle Troll and tagged , , , . Bookmark the permalink.