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 override animator controllers to animate different types of characters


If you have multiple types of character in your game, most probably you would like to be able to share the animation states logic between them and just replace the animation clips. Imagine that you have several types of enemies, and their combat logic is the same (they have attacks, movement, hit reactions, and so on) but they use different animation clips. For such situations, Override Animator Controllers come in handy.

Getting ready

You should have at least two characters with different animation clips ready and imported into Unity. You can also download the provided example Unity project and go to the Chapter 01 Working with animations\Recipe 09 Using override animator controllers to animate different types of characters directory. There is a scene called Example.unity there. If you open it, you'll find Warrior and Spider game objects in the Hierarchy. They have Override Animator Controllers attached, and you can examine them. If you run the game, the characters will play attack animations. The underlying logic is defined in the HumanCombat controller (found in the Animator Controllers directory). The Warrior game object uses the HumanCombat controller without overriding it, the Spider game object uses a SpiderCombat override controller.

How to do it...

To use Override Animator Controllers, follow these steps:

  1. Create a normal Animator Controller that will be used as the reference controller containing the logic of animation states. In the provided example, it is the HumanCombat controller, created with Warrior animations.
  2. You can attach this controller to your first character (its Animator component) and use it as previously.
  3. Create an Override Animator Controller by right-clicking on the Project View and choosing CreateOverride Animator Controller.
  4. Select the newly created override controller and go to the Inspector tab.
  5. Drag and drop your original/reference Animator Controller to the Controller field of the newly created override controller.
  6. You will see all your original animation clips listed on the left and fields for overriding those animation clips.
  1. Drag and drop the animation clips from your second character to the override fields corresponding with original animation clips of your first character. In the provided example, Human animations are replaced with Spider animations.
  2. Assign the Override Animator Controller to the Controller field of the Animator component of your second character.

How it works...

Override Animator Controller only replace animation clips from your original Animator Controller. The logic of the original controller stays the same (so you can also use the same scripts to set the same parameters and so on). It is extremely useful for creating NPC characters in your games. You create the Animator Controller once, you write the scripts driving the controller once and only change the animations.

Note

Your original Animator Controller has to have animation clips. You cannot override empty animation states.