AI For Games: Week 8

Enemy Patrols

I’m going to make the rooks patrol the map.

Goal

My goal is to have enemies move along a path to form a ‘patrolling’ effect. I have planned this from the start but not yet implemented it, finally I can get around to it.

Methods

Godot has a path node that I can draw paths in editor for my enemies to follow, but instead I’ll just place a target node and have the enemy pathfind there. It’s a lot less editor work and it’s the same amount of code to do it my way.

A patrol path

So, in our world scene we’ll add a load of enemies and a load of nodes that mark where the enemy will be patroling to. The enemy will patrol between its starting location and its closest patrol point. So, we use godot’s linear interpolation function to interpolate between the position of the enemy and the target node, when the interpolation is done we move on to the next point.

We have to make a load of nodes the player can navigate to, so I make a parent node which the rooks get from and they look through the children of that node until it finds the closest one to it. Perhaps I should manually select which node they navigate to so they can have overlapping or distant paths.

Conclusion

My enemies now patrol the map! This will really add some more tension and complexity.




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Voronoi Graphics: Drawing shapes across voronoi edges
  • Markov Chains
  • AI For Games: Week 11
  • AI For Games: Week 10
  • AI For Games: Week 9