Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 5.x Animation Cookbook

You're reading from   Unity 5.x Animation Cookbook An advanced solution to all your Animation problems

Arrow left icon
Product type Paperback
Published in May 2016
Publisher Packt
ISBN-13 9781785883910
Length 328 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Maciej Szczesnik Maciej Szczesnik
Author Profile Icon Maciej Szczesnik
Maciej Szczesnik
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Working with Animations FREE CHAPTER 2. Working with the Animation View 3. 2D and User Interface Animation 4. Character Movement 5. Character Actions and Expressions 6. Handling Combat 7. Special Effects 8. Animating Cutscenes 9. Physics and Animations 10. Miscellaneous

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 animations: Wave 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.

You have been reading a chapter from
Unity 5.x Animation Cookbook
Published in: May 2016
Publisher: Packt
ISBN-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.
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 $19.99/month. Cancel anytime