How it works...

We create a new path, taking the initial node as a starting point, and apply ray casting to the next node in the path until we get a collision with a wall between our current node and the target node. When that happens, we take the last clear node, put it in the new path, and set it as the current node to start casting rays again. The process continues until there are no nodes left to check and the current node is the target node. That way, we build a more intuitive path.

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition 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.