Book Image

Unity 5.x Animation Cookbook

By : Maciej Szczesnik
Book Image

Unity 5.x Animation Cookbook

By: Maciej Szczesnik

Overview of this book

This recipe-based practical guide will show you how to unleash the power of animation in Unity 5.x and make your games visually impeccable. Our primary focus is on showing you tools and techniques to animate not only humanoid biped characters, but also other elements. This includes non-humanoid character animation, game world creation, UI element animation, and other key features such as opening doors, changing lights, transitioning to different scenes, using physics, setting up ragdolls, creating destructible objects and more. While discussing these topics, the book will focus on mecanim, the Unity 3D animation tool, and how you can use it to perform all these tasks efficiently and quickly. It contains a downloadable Unity project with interactive examples for all the recipes. By the end of this book, you will be confident and self-sufficient in animating your Unity 3D games efficiently.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using animations from multiple assets


At times it is very convenient to separate animations to multiple assets. A common scenario is to have rigged models separated from animations or different animation types separated from each other (combat from movement, movement from actions, actions from cut scenes, and so on). This recipe shows how to do it for both Humanoid and Generic rigs.

Getting ready

Before we start, you should prepare and import at least two assets containing animations. If you are using a Generic rig, make sure to have the same rig in both assets. You can also use the provided example Unity project and go to the Chapter 01 Working with animations\Recipe 06 Using animations from multiple assets. There is a scene called Example.unity file there. In the scene Hierarchy you can find a Character game object. It has an attached Animator Controller in which you can find two animations: Idle and Wave. In the Rigs directory, you will find the Character.fbx asset containing only a rigged character along with the Idle.fbx and Wave.fbx assets containing the corresponding animations.

Note

If you are exporting FBX files from Blender, make sure to disable the Add Leaf Bones option in the exporter. If you are exporting just the rig and animations (without a mesh), add an empty object to the scene. If you will not do this, your rig could be messed up a bit after import.

How to do it...

To use animations from multiple assets, you need to follow these steps:

  1. Import the files to Unity.
  2. If you are using the Generic rig, you have to set the Avatar Definition to Create From This Model on your character (or reference character if you plan to have multiple characters with the same rig). For each imported animation asset, set the Avatar Definition to Copy From Other Avatar and choose the avatar of your character or reference character. To do so, you need to unfold the character asset, find the avatar, and drag and drop it to the Source field in the Inspector tab.
  1. If you are using a Humanoid rig, you don't have to copy the Avatar Definition (you still can if your rigs are exactly the same; that way you will have fewer avatars in your project, making it easier to find the ones you need).
  2. Create or open an Animator Controller.
  3. Assign animations from different files and build transitions between them.
  4. Run the game to see the animations work.

How it works...

All Generic rigs can use animations from multiple assets that share the same Avatar Definition. To share the same Avatar DefinitionGeneric rigs have to have exactly the same rigs (the same hierarchy, the same bone names and transforms). All Humanoid rigs can use animations from multiple assets that are also set to Humanoid. Additionally, they don't need to have the same rigs because Unity automatically retargets all humanoid animations.