In this section, we will explore obstacle avoidance. As a first step, we need, of course, obstacles. We will set up a scene similar to the one shown in the following screenshot. Then, we will create a script for our character so that it can avoid the obstacles while trying to reach the target point. The algorithm presented here uses the raycasting method, which is very straightforward, but on the other hand, it can only avoid the obstacles that are blocking the path directly in front of it:
To create this, we make a few cube entities and group them under an empty game object called Obstacles. We will also create another cube object called Agent and give it our obstacle avoidance script. We will then create a ground plane object to assist in finding a target position:
It is worth noting that this...