Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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 2. Working with the Animation View FREE CHAPTER 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

Importing skeletal animations

This first recipe shows how to import a skeletal animation from a 3D package. It assumes that you have an animation already prepared. We are going to bring the file to Unity and show where you can adjust the import settings. We will not jump into too much detail for now to make the import process as quick as possible. We will cover all the settings in further recipes.

Getting ready

Most animations are created in external 3D packages such as Maya, 3ds Max, Motion Builder, or Blender 3D. Make sure you have prepared a 3D model with a skeleton, the model is skinned, and you have created at least one animation. You can also download the provided example; open the project in Unity and go to this folder: Chapter 01 Working with animations\Recipe 01 Importing skeletal animations\Sheep Model. You will find an imported FBX file called Sheep.fbx there.

How to do it...

To import a skeletal animation, you need to follow these steps:

  1. Export a skinned model and its skeleton (called rig in Unity) to FBX format.
If you are using Blender, you don't have to manually export the file to FBX format. Simply drag and drop the file to your Assets folder. Unity will use Blender FBX exporter in the background. Additionally, you will be able to open the file by double-clicking on it in Unity. After you edit and save it, Unity will reimport it again. It is a very convenient way of editing animations as you don't have to go through the export-import process each time you make a change.
  1. Drag and drop the exported file into any subfolder in the Assets folder in your project or go to AssetsImport new asset and choose your FBX file.
  1. Select the imported file and navigate to the Inspector tab. Click on the Rig button:
  1. Here you can specify the type of the rig to use. For bipedal characters, use the Humanoid option, for all the rest choose Generic. We use a sheep model in this example, so we need to choose the Generic rig. Differences between those options are described in the How it works section.
  2. Leave all the other inputs as defaults.
  1. Click on the Animations button. If an Unapplied import settings window appears, click on Apply.
  1. Make sure the Import Animation checkbox is checked.
  2. Click on the Apply button in the lower right corner of the Inspector (just above the Animation Preview). You may need to scroll the Inspector down.
  1. You should be able to see all imported animation clips as child assets of your imported FBX file.

How it works...

Unity uses four different rig configurations:

  • Generic rig: This one is used for quadrupeds, spiders, and other non-humanoid characters. It uses Unity's Mecanim system for controlling animation flow. It can use root motion if you provide a Root nodea bone responsible for character movement.
  • Humanoid rig: This one is used for humanoid characters only. It also uses Mecanim system for controlling animation. If you are using Humanoid rigs, you have more options for importing animations. The biggest advantage is automatic animation retargetingyou can use the same animation clip on various types of humanoid characters (for example, a dwarf and a troll).
  • Legacy: This option is used mostly for backward compatibility with previous versions of Unity. It is similar to the Generic rig but uses scripts instead of Mecanim for controlling animation flow. I recommend using Generic rig instead.
  • None: This last option turns off the rig and disables animation import.

We will discuss differences between Generic and Humanoid rigs further in the next recipe.

There's more...

  • Imported animation clips are also listed in the Clips section of the Animations tab.
  • You can add new clips by clicking on the plus button below the Clips section. You can also remove clips by clicking on the minus button.
  • You can rename each clip by using the input field above the Source Take drop-down menu.
  • You can choose the source take (the animation stored in your FBX file) for each animation clip with the Source Take drop-down menu.
  • You can also trim the animation clip by editing the Start and End input fields.
If you are using Blender, make sure to rotate the rig -90 degrees in the X axis, apply the rotation in Blender and then rotate it again, +90 degrees in the X axis. The rotation of the rig in Blender should be: 90 X, 0 Y, and 0 Z. Your model should be facing the -Y axis in Blender (when you change the view to FRONT, you should see the face of your character). Blender and Unity use different axes alignment: in Blender, Z is up and Y is back; in Unity Z, is front and Y is up. This little trick solves the problem. Your model after import should have 0 rotation and should be facing the Z axis. It is important for moving objects (such as characters) and rig configuration. If you don't do this, your model will have -90 X rotation after the import.
lock icon The rest of the chapter is locked
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
Banner background image