Chapter 10. Animation and AI

Part of having realistic game AI is having characters play animations at times appropriate to the AI character's state. In this chapter, we will look at animation and how it is integrated with RAIN, both with Unity's legacy animation system and Mecanim.

In this chapter, you will learn about the following:

  • Why animation management is an important part of game AI
  • Managing animation with behavior trees and Unity's legacy animation
  • Managing animation by AI with Unity's Mecanim animation system

An overview of animation

When you think about game AI, first you probably think about things such as creating virtual minds and making characters "think". When I first started learning about game AI years ago, I didn't think animation was really important for game AI since it wasn't part of creating a virtual mind. But then I attended some AI sessions at the Game Developers Conference and found out that one of the most discussed topics in AI was integrating AI with animation systems; this is when I realized it really is an important part of game AI. This makes sense since game AI is about modeling real thinking instead of focusing on giving characters the appearance of thinking, so having the characters play animations that match their state is important. We can think of animations as just a visual depiction of the current state of the character.

The method we'll look at for integrating animations with the AI is RAIN's animation integration with Unity. RAIN has an Animation tab (with an icon of a running man) in its AIRig. In this tab, animation clips can be configured using one of two RAIN animators.

RAIN has a BasicAnimator option to configure clips with Unity's legacy animation and a MecaninAnimator option used to set up Mecanim animations. Once these animations are set up, RAIN has an animate node in its behavior tree system that can be used to call different animation states. Usually, this is done in conjunction with a parallel node with the animate node being one of its children. This way the animation can run at the same time as the other logic is being executed in the tree.

The best way to see this is through demos. For these, we need to have two characters: a legacy and a Mecanim setup. To do this, our demo project will use two demos that are made by Unity and can be downloaded for free from the Asset Store. The first is Penelope Complete Project v1.1. This contains the Penelope character we will use for the Unity legacy demo. The other project is Mecanim Example Scenes v1.0 that will be for the Mecanim setup character, Teddy. Create a new project and import both of these and the latest RAIN package. Once these are set up, we can start building the animation demo.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.58.122