Obstacle avoidance
If the game objects are exhibiting the group behaviors, then it's really important to make them avoid collision with each other. Also, there can be multiple obstacles on the way, which the characters have to avoid intelligently.
Getting ready
The following approach will be used to implement the obstacle avoidance behavior:
- Create three feelers in front of the player object
- Let all the three feelers sense the obstacles on the way
- Redirect the player in the opposite direction if the feeler has sensed any obstacles
How to do it
Follow the following algorithm to achieve the obstacle 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 Left_Feeler = player->Get velocity; // vector Left_Feeler = Left_Feeler.normalize(); // vector Right_Feeler = player->Get velocity; // vector...