O'Reilly logo

Unity 4.x Game AI Programming by Thet Naing Swe, Aung Sithu Kyaw, Clifford Peters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Avoiding obstacles

In this section, we'll set up a scene as shown in the following screenshot, and make our AI entity avoid the obstacles while trying to reach the target point. The algorithm presented here using the raycasting method is very simple, so it can only avoid the obstacles blocking the path in front of it. The following screenshot will show us what our scene will look like:

Avoiding obstacles

A sample scene set up

To create this, we make a few cube entities and group them under an empty game object called Obstacles. We also create another cube object called Agent and give it our obstacle avoidance script. We then create a ground plane object to assist in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required