Reader small image

You're reading from  Unity Artificial Intelligence Programming - Fifth Edition

Product typeBook
Published inMar 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781803238531
Edition5th Edition
Languages
Tools
Right arrow
Author (1)
Dr. Davide Aversa
Dr. Davide Aversa
author image
Dr. Davide Aversa

Dr. Davide Aversa holds a PhD in Artificial Intelligence (AI) and an MSc in AI and robotics from the University of Rome La Sapienza in Italy. He has a strong interest in AI for the development of interactive virtual agents and procedural content generation. He has served as a program committee member for video game-related conferences such as the IEEE conference on computational intelligence and games, and he also regularly participates in game-jam contests. He also writes a blog on game design and game development.
Read more about Dr. Davide Aversa

Right arrow

Avoiding obstacles

In this section, we explore obstacle avoidance. As a first step, we need, of course, obstacles. So, we set up a scene similar to the one shown in Figure 6.6. Then, we create a script for the main character to avoid obstacles while trying to reach the target point. The algorithm presented here uses the raycasting method, which is very straightforward. However, this means it can only avoid obstacles that are blocking its path directly in front of it:

Figure 6.6 – A sample scene setup

We make a few cube entities and group them under an empty game object called Obstacles to create the environment. We also create another cube object called Vehicle and give it the obstacle avoidance script. Finally, we create a plane object representing the ground.

Figure 6.7 – Here is the structure of the scene's Hierarchy

It is worth noting that the Vehicle object does not perform pathfinding, that is, the active search...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Unity Artificial Intelligence Programming - Fifth Edition
Published in: Mar 2022Publisher: PacktISBN-13: 9781803238531

Author (1)

author image
Dr. Davide Aversa

Dr. Davide Aversa holds a PhD in Artificial Intelligence (AI) and an MSc in AI and robotics from the University of Rome La Sapienza in Italy. He has a strong interest in AI for the development of interactive virtual agents and procedural content generation. He has served as a program committee member for video game-related conferences such as the IEEE conference on computational intelligence and games, and he also regularly participates in game-jam contests. He also writes a blog on game design and game development.
Read more about Dr. Davide Aversa