• Register

Demons with Shotguns is a competitive platformer featuring old school, fast paced, twitch style arena shooting action where you battle for the souls of your friends!

Post news Report RSS Finding Purpose in War

Even enemies need a goal to stride towards. See how enemy AI is improving in Demons with Shotguns.

Posted by on

With the foundation of End of Times fully in place, I can start working on improving the enemy AI. To start, I'll be working on improving the pathfinding on enemies so that they can travel to a particular spot in a arena, rather then roam randomly. Currently, all enemy AI have a simple "bump and switch" algorithm defining how they move. What this means is, an enemy will roam in a particular direction until they detect a collision, or a ledge, in which case they'll simply turn around. While this is serviceable, and many arena shooters use this type of enemy AI, I'd like the player to face off against smarter, more worthy adversaries!

To allow enemies to traverse a arena more fully (no more be containing to a single area/platform), I started to build a network of nodes throughout the arena. These nodes will tell enemies where they can go, and they even serve as jump pads, telling an enemy that they can jump and how high they need to jump.

Ignore the red numbers, those are enemy spawn points and not related to pathfinding. Instead we're interested in the yellow dots and lines connecting them. Currently, the lines don't do serve any purpose (they will soon, more on that later!). At this iteration, whenever an enemy collides with one of the yellow dots (our Nodes), it will tell the enemy three things, the speed at which they can continue to travel at (each node has a left speed and right speed value), and a value to let the enemy know they should jump, and by how much can they jump.

At this point, the enemy doesn't have any goals or desires to travel to any particular node in the arena, they are still roaming somewhat aimlessly, but now the enemy can just jump around to other platforms and be steered in a particular direction. This is good a start! But we can do better. What if we want the enemy to travel to a particular node or object within the arena, say hunt our player?

One way of achieving that is by simply telling the enemy which direction the goal is relative to themselves (is the object to my left, or right?). Thankfully, we can easily calculate that using vector dot product formula. Depending on the angle of the dot product, we'll know if the object is the left, or right, telling the enemy AI which direction to travel in.

In the GIF above, the enemy starts to travel towards the direction of the player once he has spawned, only to be treated to a buck shot. Poor Nomed. He had it coming though.

All done! We have our enemy hunting a particular goal in a arena, using nodes to steer them in the right direction.

Well, not quite. There's still two things we need to consider at this point. What if there are multiple objects the enemy could care about? How do we select which one is most desirable? And second, right now, there's nothing telling the enemy which path is best to travel. There's still no real pathfinding going on.

Let's address the first issue, determining which object is most desirable to head towards. What if we could have our nodes rate their current desirability, based on several variables such as is if the player or a particular game object near by, and allow enemies select the most desirable node to travel to?

And that's exactly what I did! In the above GIF, the large yellow circles for each node is the area in which a node will check to see if there is any particular object they care about is near by (right now, just the player). The number within the circles is the nodes current desirability rating. Each nodes as a default desirability of 100. Once a player comes within range of the node, it will add 300 to it, for a total desirability rating of 400. When the player leaves the node area, it'll go back to 100.

The enemy can now search through all the nodes and determine which one has the highest desirability rating, and thus is the most desirable to travel to. This lays a nice foundation to give enemies a system to more smartly traverse the arena and achieve a particular goal.

We still haven't addressed our pathfinding requirement. At this point, enemies don't follow a particular path to a node, per say. They are still just moving left or right until a node tell them to jump (actually, they'll only jump if their current target node is above them), or their target node changes desirability and heads in that general direction. This does work well, but there are some edge cases where this breaks and a more robust system is need (in the GIF above, if the most desirable node is in the platforms above only reached by portals, the enemy doesn't know how to get there properly yet).

More astute readers are probably screaming "A*! A*! A*!". We'll get there, soon enough ;) I'll save that for part 2, next time!

So this is the current state of the enemy AI in Demons with Shotguns. The short term goal is to have smarter, more worthy enemies to face off against. The long term goal, possibly introducing bots into the Versus game modes. We'll see how things develop!

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: