Waypoints for your AI, making it modular.

Edward Kim
2 min readApr 27, 2021

Making a waypoint system for AI patrols. Sounded not too bad, but in reality it was quite the struggle. I had first created a basic AI for one of the guards, however modularity is king, so I set off to make a script that could be used by all the guards.

So I had to take this, which only would work for the first guard, and recode it in a way where each guard would separately check their own waypoints and determine what to do.

In the end we had ended up with this. Using proper variables and even going into LISTS, depending on certain if check we would increment the target waypoint to the next, and to the next, and even reverse it so they would loop.

The coroutine ended up looking as above but it was mainly needed due to the ability to use “yield” so I could have the guards wait at certain waypoints.

The script broke and fixed itself, then broke again, and some things weren’t even related to the script. In the end however it was all worth it. Any time I want to make a new guard, I just have to physically set the waypoints on the map, and the script will just do its magic.

Modularity is KING and in the long run, is a amazing timesaver.

See you next post.

--

--