Reader small image

You're reading from  Unity 5.x Animation Cookbook

Product typeBook
Published inMay 2016
Reading LevelExpert
PublisherPackt
ISBN-139781785883910
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Maciej Szczesnik
Maciej Szczesnik
author image
Maciej Szczesnik

Not interested. Too busy with current game project. Source: Linkedin.
Read more about Maciej Szczesnik

Right arrow

Looping, mirroring and offsetting the animations


Unity allows editing the animations to some extent after they're imported. It can save a lot of work and greatly speed up your workflow.

Getting ready

Before we start, you should prepare and import a Humanoid rig with at least one animation. You can also use the provided example Unity project and go to the Chapter 01 Working with animations\Recipe 07 Looping mirroring and offsetting animations directory. There is a scene called Example.file there. In the scene Hierarchy, you can find a Mirror game object. It has an attached Animator Controller in which you can find two animationsWave and WaveMirror. In the Rigs directory, you will find the Mirror.fbx asset. If you select it and go to the Inspector, and to the Animations tab, you can find normal and mirrored animation examples, as well as looped animation examples (Idle and IdleMirror).

How to do it...

To set an animation to loop, you need to go through the following steps:

  1. Select the animated asset and go to the Animations tab.
  2. Check the Loop Time checkbox and click on the Apply button. The animation is looped.
  3. If your animation's first and last frames don't match perfectly, you can force them to match with the Loop Pose checkbox. It is not recommended to use this option for animations that have matching first and last frames.

To offset an animation, you need to go through the following steps:

  1. Select the animated asset and go to the Animations tab.
  2. Select your animation and make it loop (Loop Time checkbox).
  3. Enter a value in the Cycle Offset field, below the Loop Pose checkbox.
  4. Click on the Apply button.

To mirror an animation, you need to go through the following steps:

  1. Select the animated Humanoid asset and go to the Animations tab.
  2. Find the Mirror checkbox on the bottom of the animation settings.
  3. Check the Mirror checkbox and click on the Apply button. The animation is mirrored.
  4. Mirroring animations works only for Humanoid rigs.

How it works...

  • Looping animations: This is a common technique used for all cyclic movements (walk and run cycles, idle animations, and so on). If you don't set an animation to loop, it will play once and freeze on the last frame.
  • Offsetting animations: Sometimes it is convenient to offset the cycle of a looped animation. It is often used with the Mirror option for steering animations (clips used to turn the character while moving). We will be showing that in the Using root motion to steer a character recipe in Chapter 4Character Movement.
  • Mirroring animations: This option works only with Humanoid rigs. It is used to flip the animation left to right and can save up to 50 percent of steering animations when combined with the Offset Cycle option.

There's more...

You can also mirror and offset animation states in the Animator Controller. If you select an animation state and go to the Inspector tab, you can find the Mirror and Cycle Offset options. There is also an option to use Animator Controller parameters to switch the Mirror option on and off and set the Cycle Offset. You need to have a Boolean parameter defined for the Mirror option and a float parameter for the Cycle Offset. Those settings will be automatically synchronized with the parameters. Whenever you change a parameter value, the setting will also be changed.

Previous PageNext Page
You have been reading a chapter from
Unity 5.x Animation Cookbook
Published in: May 2016Publisher: PacktISBN-13: 9781785883910
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Maciej Szczesnik

Not interested. Too busy with current game project. Source: Linkedin.
Read more about Maciej Szczesnik