Reader small image

You're reading from  Unity AI Programming Essentials

Product typeBook
Published inDec 2014
Publisher
ISBN-139781783553556
Edition1st Edition
Tools
Right arrow
Author (1)
Curtis Bennett
Curtis Bennett
author image
Curtis Bennett

Curtis Bennett has been a developer in the games and computer graphics industry for several years. He has worked on developing immersive virtual environments, published research in visual simulation, taught college courses in game development, and worked for various game studios, and he was also an engineer on early versions of the RAIN AI plugin for Unity. Currently, he is the Technical Director for Creative Services at Ideum, which focuses on creating interactive media projects.
Read more about Curtis Bennett

Right arrow

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...

The AI animation demo


As the first step, create a new scene and add a plane to it with a scale of X equal to 10, Y equal to 1, and Z equal to 10 to give us a floor where characters can walk around (and if you want, change its material so it's not white). Then, add the penelope model to your scene that's at Assets/Objects/penelopeFX. Next, we'll do our basic RAIN setup and add a navigation mesh by going to RAIN | Create NavMesh. Make sure the navigation mesh will cover the floor, so change its Size to 100 and then generate the mesh. Next, create a waypoint route by going to RAIN | Create Waypoint Route, rename it PenelopeRoute, and add a few points in front of the penelope model for the character to walk. Lastly, add a RAIN AI object by selecting penelope and going to RAIN | Create AI. Your screen should look similar to the following screenshot:

The scene for the AI animation demo

Note

If you need more details on how to set up a scene with a character patrolling a path, refer to Chapter 2, Patrolling...

Summary


In this chapter, we looked at how to integrate animation with our AI. We saw how to use RAIN's animate node to change the character animation from its behavior tree with both Unity's legacy animation system and Mecanim. In the next chapter, we will go back to discussing character movement across a scene. We will look at more advanced uses of navigation meshes and how to create them in more detail to give our characters better movement.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Unity AI Programming Essentials
Published in: Dec 2014Publisher: ISBN-13: 9781783553556
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Curtis Bennett

Curtis Bennett has been a developer in the games and computer graphics industry for several years. He has worked on developing immersive virtual environments, published research in visual simulation, taught college courses in game development, and worked for various game studios, and he was also an engineer on early versions of the RAIN AI plugin for Unity. Currently, he is the Technical Director for Creative Services at Ideum, which focuses on creating interactive media projects.
Read more about Curtis Bennett