Game Development Reference
In-Depth Information
How to do it
Follow the following algorithm to achieve the obstacle avoidance behavior in the project.
1. The visual explanation of the technique is shown in the following screenshot:
2. 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
Right_Feeler = Right_Feeler.normalize(); // vector
This will project the feeler in front of the player.
Front_Feeler = Front_Feeler * FeelerLength; // vector
Front_Feeler = Front_Feeler + player->location;
Left_Feeler = Left_Feeler * FeelerLength; // vector
Left_Feeler = Left_Feeler + player->location;
Left_Feeler->x = Left_Feeler -> x - player-> width;
Right_Feeler = Right_Feeler * FeelerLength; // vector
Right_Feeler = Right_Feeler + player->location;
Right_Feeler->x = Right_Feeler -> x + player-> width;
Now we have left, right, and front feelers. So whenever these feelers will sense any
object in their way, they will push the player away from the obstacle.
Search WWH ::




Custom Search