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:
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.
It is worth noting that the Vehicle object does not perform pathfinding, that is, the active search...