Book Image

Unity Character Animation with Mecanim

By : Jamie Dean
Book Image

Unity Character Animation with Mecanim

By: Jamie Dean

Overview of this book

Game animation for independent developers has taken a giant leap forward with Unity 5's Mecanim toolset, which streamlines the import/export, retargeting, and many other aspects of the character animation workflow. Unity Character Animation with Mecanim is a great primer for getting to know the nuts and bolts of Mecanim and other character animation related tools in Unity 5. It offers you step-by-step instructions for preparing and exporting rigged models and animation sequences from commonly used 3D packages, such as Maya, 3ds Max and Blender. This book explores the new set of animation tools introduced with Mecanim in Unity 5. Approaching its subject matter through a typical genre–a zombie action game, character animation techniques are explored using real examples of player input and interaction, enemy behavior, and other aspects of game dynamics. As the book progresses, the reader will understand how these elements fit together in a small game development workflow. We will begin with a demonstration of the process of getting a rigged character into Unity 5 and setting it up to use provided animation sequences. We will also consider a few industry standard 3D packages and how these can be used to rig a humanoid character for use in Unity 5. We will demonstrate the retargeting capabilities of Mecanim’s Humanoid Animation type by adjusting motion sequences to fit disparate character types in our game. After this, we will look at Ragdoll physics and the implementation of this commonly used technique in a Mecanim workflow. The book culminates with a thorough dissection of the enemy character AI script incorporating the Mecanim elements detailed in the previous chapters. Unity Character Animation with Mecanim will provide you with a detailed exploration of the interaction between game development and character animation, and will broaden your understanding of the rich animation toolset within Unity 5
Table of Contents (16 chapters)
Unity Character Animation with Mecanim
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
The Zombie Attacks!
Index

Preface

In the past few years, Unity has proved itself to be a versatile, user-friendly platform for game production and other interactive applications. With it, developers can rapidly assemble game menus and interfaces, build levels, animate characters, and define how these elements interact with each other.

Compared to other development tools, Unity is artist-friendly, centering on a Scene viewport window and controls that will be familiar to anyone who has worked with 3D software. Like all game engines, it requires scripting to enable any complex functionality, but coding can quickly be tested and adjusted making for a less-frustrating experience for anyone from a non-programming background.

Unity's easy-to-learn drag and drop functionality has endeared it to enthusiasts and professionals alike. Its multiplatform publishing capabilities streamlined the creation of all sorts of games played on PC, Mac, iOS, Android and consoles.

The personal edition of Unity can be downloaded for free, making it suitable for entry-level game developers. The online manual and scripting reference, in addition to the thriving developer community, make it easy to find support and get queries answered.

The addition of Mecanim to Unity gives the independent game developer an even more expansive toolset, making it possible to handle a significant part of the character animation process without the use of additional software. It makes retargeting, retiming, and adjusting existing animations a simple task without the usual problems that accompany importing and exporting data between applications.

The modeling toolset within Unity is extremely limited—primitive objects such as spheres, cubes, and planes can be assembled—but if it is the actual modeling and texturing of characters and levels that you are most interested in, you will need a general 3D package such as 3ds Max, Maya, or blender. These aspects of building a game are well addressed in other publications.

The context

In order to closely correspond to the development of a real game, the projects in this book follow a theme of a typical first-person action game—the sort that is often found to be played on PC, console, and mobile platforms—the context is the zombie apocalypse. During the game, our player must negotiate his or her way out of an office complex full of zombies. In terms of character animation, this will offer us plenty of variety in the type of movement required by the player and enemies.

What this book covers

This book will take the reader through the different processes involved in the character animation aspect of game development. It will explain the basic animation tools within Unity, as well as the dynamic Mecanim toolset and how it can be used in the game animation context.

Chapter 1, The Zombie Attacks!, introduces the Mecanim interface and explains how rigged characters can be imported to Unity and quickly set up with animation.

Chapter 2, Rigging Characters for Unity in 3ds Max and Maya, explains the relationship between the Unity engine and commonly used 3D software and how characters can be prepared within external software to function smoothly once imported to Unity.

Chapter 3, Interacting with the Environment, compares a few different strategies for making a character interact convincingly with the environment.

Chapter 4, Working with Motion Capture Data, walks you through the process of adapting motion capture files to animate your character with Mecanim's toolset.

Chapter 5, Retargeting Animation, considers the reuse of animation clips and how animation can be adapted within Unity to suit different character types.

Chapter 6, Talking Heads, demonstrates Mecanim's facial animation capabilities and the scripting necessary to get these working in a game.

Chapter 7, Controlling Player Animation with Blend Trees, explores more of the advanced features of the Animator panel, defining smooth blending between different animation clips with a limited implementation of scripting.

Chapter 8, Implementing Ragdoll Physics, compares the use of real-world physics with the character controller component and how these can both be implemented in a character setup.

Chapter 9, Controlling Enemy Animation with AI and Triggers, demonstrates how scripted behavior and Unity's navMesh navigation system can be used to control enemy character animations within a game.

What the book does not cover

Modeling, texturing of assets in 3D software, scripting game states, and GUI within Unity. These aspects of game development are beyond the scope of this book.

What you need for this book

Understanding key animation concepts is necessary to complete the chapters in this book. In addition, you will need the following:

  • Unity 5 installed on your machine (Mac or PC). The free personal version of the software is sufficient for all of the project content in this book. This can be downloaded from the Unity webpage.

  • A little understanding of 3D software, x, y, and z coordinates, translating, rotating, and scaling elements within the Unity viewer interface.

  • A basic understanding of Unityscript or C# will be helpful to complete the projects, though the code that is included is clearly explained.

  • Additional 3D software is useful, but not required. The industry standards Autodesk Maya and 3ds Max both have free 30-day trials, which can be downloaded from the main Autodesk website. Blender is a free alternative.

Who this book is for

This book focuses on the character animation aspect of game production in Unity.

If you are completely new to Unity, it is recommended to read through some of the basic introductory material documentation on the official site. If you have experience working with an older version of the software, then this book should give you a good idea of how Mecanim can be used in your pipeline.

If you are new to animation, this book uses some character animation terminology that you may not be familiar with. Where possible, I have explained these terms.

My approach to writing this book comes from an artist, rather than coder background. If your motivation for understanding character animation in Unity is to showcase your artwork in a demo or even a full-scale game, you have come to the right place!

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Choose an appropriate file name for the scene, such as Chapter1_1."

A block of code is set as follows:

var health : int = 10;
var healthLimit : int = 10;

function AddHealth (increase : int)
{
    health += increase;

    if (health > healthLimit)
{
        health = healthLimit; 
   }

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on the Model tab."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from:

https://www.packtpub.com/sites/default/files/downloads/B03192_ColoredImages.pdf

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.