A different kind of patrolling

I watched a youtube video on ‘dynamic patrolling’ that was interesting. Instead of a predefined path, at start up all of the waypoints store all of their neighbor waypoints within a preset range. Then, when a unit reaches a waypoint and asks for the next waypoint it randomly picks from it’s neighbors.

I took that idea and added my own innovation. Instead of randomly choosing a neighbor, each waypoint keeps track of how long it has been since it was last visited and the waypoint chooses the neighbor that was least recently visited.

I created SearchPath as subclass from the path script in the course so the class AI script could use either one.

This actually has quite a few cool side effects:

  1. All the waypoints end up getting visited but it is nearly impossible for the player to guess where an enemy is going next.
  2. You can add more waypoints without having to worry about what order they appear. It will simply become a new option as long as it’s in range of at least one existing waypoint.
  3. You can easily add multiple enemies to the same SearchPath and they will end up doing a really good job of spreading out and searching around the different areas of the path. In the Sandbox scene I added two of these paths with 20-25 nodes each and assigned them to squads of 8 enemies. From the player’s point of view it kind of feels like they are ‘everywhere’ and coming at you from angles you didn’t expect.

Anyway, I thought I’d share that idea with the team because it’s a really neat and simple addition to the enemy AI. I’m using both kinds of patrolling in my game.

3 Likes

Privacy & Terms