Getting Aggroed

In my spare time recently, I have been playing almost exclusively Dark Souls III and Clash Royal and these two games have both made me wonder how it is that they are coding their AI targeting system. Things can seem pretty baseline and consistent for a number of enemies and then out or no where one enemy will just do their own thing completely independent of what all of the enemies of the same type do. I know obviously that every enemy is going to have a set aggro range, but it seems like some of these enemies just go rouge sometimes.

Using Dark Souls as an example, there are your obvious factors such as movement speed and the enemy’s direction, but what about some of the non-humanoid creatures? [SPOILERS] There are enemies that are giant crabs that you face in a couple of different areas in mid-game, that will basically aggro to you almost as soon as they come into view if they are on the same plane. These enemies have a large amount of health and do a solid amount of damage while almost always being in groups, making them a pain to deal with every time that you encounter them. However, at the same time even some of the most difficult base enemies that don’t respawn, like the black knights, you can walk right up behind them and get off a quick back-stab before they completely mash you into the ground.

As for Clash Royal, there are the obvious factors as well such as flying, ground, troop, or building, but what sets priority when multiple targets are in the area? For anyone that has played Clash Royal I’m sure they understand the annoyance of getting up to a tower and the opponent putting down some kind of troop that pushes you off of attacking the tower, when just the game before you tried the same thing and they just destroyed your tower anyway.

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Getting Aggroed

  1. jcl259 says:

    I am guessing there is a timed update function, that runs say every 0.05 seconds for example. Every time this function runs, all the enemies distances are calculated from your current position. Certain targets can be ignored (like flying if your ground only). Its also possible to set priorities. So the tower could be set to a low priority compared to the defensive tower. So if a defensive tower is slightly farther away than the crown tower, your unit will prioritize the defensive tower. It is primarily based on closest target but these functions can get very complex. I personally love writing AI code. Its my favorite part about writing a game. I’m guessing they have a base class for AI behavior with many settings like a preferred target type (defense/any/gound_only) and other variables like is_distracted_when_hit? which would make a troop unlock from its current target and switch to whatever just hit them (archers and muskateers do this). Using a class for all AI isn’t always possible but in clash royal it is since they all have similar behavior. Clash Royal isn’t all that difficult to write the AI behavior. It gets much trickier with 3D AI when the enemy/friendlies don’t move on a single plane. Even the air units move on a plane in clash royal so this is fairly simple. What I think is more impressive with Clash Royal is that two players must be looking at the exact same battle via the internet. There’s always going to be some lag between the players and I think they did a good job at making this pretty tough to detect. I’m guessing the games are actually running on their server and the two players send their moves and receive where all the objects are. I think if they incorporated team battles (ie 2v2 or 3v3) into Clash Royal the game would be very impressive and much more fun. Incorporating teamwork into a game like this would really bring it to another level.

Leave a Reply