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 Artificial Intelligence Programming

You're reading from   Unity Artificial Intelligence Programming Add powerful, believable, and fun AI entities in your game with the power of Unity

Arrow left icon
Product type Paperback
Published in Mar 2022
Publisher Packt
ISBN-13 9781803238531
Length 308 pages
Edition 5th Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Dr. Davide Aversa Dr. Davide Aversa
Author Profile Icon Dr. Davide Aversa
Dr. Davide Aversa
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Part 1:Basic AI
2. Chapter 1: Introduction to AI FREE CHAPTER 3. Chapter 2: Finite State Machines 4. Chapter 3: Randomness and Probability 5. Chapter 4: Implementing Sensors 6. Part 2:Movement and Navigation
7. Chapter 5: Flocking 8. Chapter 6: Path Following and Steering Behaviors 9. Chapter 7: A* Pathfinding 10. Chapter 8: Navigation Mesh 11. Part 3:Advanced AI
12. Chapter 9: Behavior Trees 13. Chapter 10: Procedural Content Generation 14. Chapter 11: Machine Learning in Unity 15. Chapter 12: Putting It All Together 16. Other Books You May Enjoy

AI in video games

Different from general AI, game AI only needs to provide the illusion of intelligence. Its goal is not to offer human-like intelligent agents but characters that are smart enough to make a game fun to play.

Of course, making a game fun to play is no trivial matter, and to be fair, a good AI is just one part of the problem. Nevertheless, if a good AI is not enough to make a game fun, a bad AI can undermine even the most well-designed game. If you are interested in the problem of what makes a game fun, I suggest that you read a good book on game design, such as The Art of Game Design, by Jesse Schell.

However, for what concerns us, it is sufficient to say that it's essential to provide an adequate level of challenge to the player. A fair challenge, in this case, means the game should not be so difficult that the player can't beat the opponent, nor too easy that winning becomes a tedious task. Thus, finding the right challenge level is the key to making a game fun to play.

And that's where AI kicks in. The role of AI in games is to make it fun by providing challenging opponents and interesting Non-Player Characters (NPCs) that behave appropriately in the game world. So, the objective here is not to replicate the whole thought process of humans or animals but to make the NPCs seem intelligent by reacting to the changing situations in the game world so that they make sense to the player. This, as we mentioned previously, provides the illusion of intelligence.

Information

It is essential to mention that AI in games is not limited to modeling NPC's behaviors. AI is also used to generate game content (as we will see in Chapter 10, Procedural Content Generation) to control the story events and the narrative pace (a notable example is given by the AI director in the Left 4 Dead series) or even to invent entire narrative arcs.

Note that a good game AI doesn't need to be a complex AI. A recurring example is the AI of the original Pac-Man arcade game. By any modern standard, the algorithm that governs the behavior of the four ghosts chasing Pac-Man can barely be considered AI. Each ghost uses a really simple rule to decide where to move next: measure the distance between the ghost and a target tile and choose the direction to minimize the distance.

The target tile might be the location of Pac-Man itself (as in the case of the Red Ghost), but it can also be something in front of Pac-Man (such as the Pink Ghost) or some other tile. By simply changing the target tile's position, the Pac-Man arcade game can give each ghost a distinctive personality and an AI that challenges us even after 40 years!

The golden rule is to use the smallest amount of AI necessary to achieve the game's design goal. Of course, we may take this rule to the extreme and use no AI if we find out that it is unnecessary. For instance, in Portal and Portal 2, all the characters are completely scripted and there is no AI involved, yet nobody complained about the lack of AI.

Information

If you are interested in diving deeper into the Pac-Man AI, I suggest that you watch this very detailed video from the Retro Game Mechanics Explained YouTube channel: https://www.youtube.com/watch?v=ataGotQ7ir8.

Alternatively, if you prefer to read, you can go to this very informative web page: https://gameinternals.com/understanding-pac-man-ghost-behavior.

Another challenge for game AI is that other operations, such as graphics rendering and physics simulation, need to share the processing power that's required for AI. And don't forget that they are all happening in real time, so it's critical to achieve a steady frame rate throughout the game. This means that game AI needs to be designed to not overtake the computational resources. This is usually done by designing an algorithm that can be interrupted and spread over multiple frames.

In general AI, many companies invest in a dedicated processor for AI calculations called an AI accelerator (such as Google's Tensor Processing Unit). However, until games have widespread access to such dedicated AI processors, we game AI developers still need to pay attention to our algorithms' performance.

The next section will provide a general introduction to the most popular AI techniques that are used in video games.

You have been reading a chapter from
Unity Artificial Intelligence Programming - Fifth Edition
Published in: Mar 2022
Publisher: Packt
ISBN-13: 9781803238531
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