Implementing wall avoidance
The AI characters will look a little odd if they collide with a wall while wandering. So, we have to make them even more intelligent so that they can seek the wall and can respond or change direction accordingly.
The wander behavior returns a force that steers the AI away from the wall to avoid collision.
Getting ready
The following approach will be used to implement the wall avoidance behavior:
Create feelers to sense the wall
We will use one feeler in front of the AI to sense the wall
When wall is detected, apply the force at the reflected vector
How to do it
Follow the following algorithm to achieve the wall avoidance behavior in the project:
The visual explanation of the technique is shown in the following screenshot:
Create feelers that will sense the wall:
Front_Feeler = player->Get velocity; // vector Front_Feeler = Front_Feeler.normalize(); // vector
This will project the feeler in front of the player.
Front_Feeler = Front_Feeler * FeelerLength; // vector Front_Feeler...