Choosing an alternative path

Our character successfully chooses a new direction every time that he approaches a wall, and now we want him to be able to move around all over the map. To make that happen, we are going to add more information into the character to let him know that if there's an available option to turn to the left or right, even if the forward path is free, the character is free to turn. We can use probabilities to determine whether the character is going to turn or not, and for this example we have chosen to give a 90% chance of choosing a new direction if one is available. That way, we can see the results happening very quickly:

   public float Speed;   public float facingLeft;   public float facingRight; public float facingBack; ...

Get Practical Game AI Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.