Avoid walking against walls

If our character is facing a wall, he will need to know that he cannot pass through that wall and should choose another option. Unless we allow the character to climb the wall or destroy it, the character will need to face a new direction that is not blocked and walk in that new unblocked direction.

We will start with a simple approach that i can be often very useful, and is perhaps the best option, depending on the type of game that we are creating. In the example that we'll be demonstrating, the character in question needs to keep moving around the level just like the Pac-Man enemies. Starting with a basic example, we give our character the freedom to choose which direction to move in, and later on we will add ...

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.