About

I'm a software engineer who works on game development part time. I teach game development (on gamedev.stackexchange.com and lynda.com). I'm always working on something, and I'll post updates here. Let me know if there's a game development topic you want to know more about, I probably know the answer, or at least where to get one.

Saturday, March 9, 2013

Fight or flight? Threat analysis


A still very much in development system in AoG is the threat system. This system is primarily used in combat. It helps entities with their fight or flight decisions.

Basically, the system takes two entities as inputs. The subject and the potential threat. The entities have some facts about them compared and a value is output determining the threat that the potential threat poses to the subject. The facts compared depend on the entities, but some common ones are:



  • Size. Larger entities are threatening to smaller entities.
  • Species relationship. Some species just have it out for each other. These relationships can even start neutral and turn sweet or sour depending on how the two species interact throughout the game. If the goblins are always stealing food from the Zanadingos, relationships are going to get rough.
  • Body threat analysis. If an entity has a number of "weapon" type appendages (claws, spikes, poison pods, etc.), it will rate as more of a threat.
  • Speed. Faster entities are more threatening because you can't get away from them if they turn out to be nasty. Scary.
  • Demeanor. Entities have a base demeanor that can vary from species to species or individual to individual. 
  • Equipment. The tools, weapons, clothing and armor an entity has visible can be an indicator to their intentions.
  • Age. With some creatures, power comes with old age, with others it's weakness. 
A threat is also rated on its distance from the subject. With factors like speed and ranged attacks adding more threat than something like age. 

Being able to calculate the exact threat, at whatever distance needed easily allows the path finding system to flee from threats, or find paths around known threats. For example, the goblin below is interested in getting to the cube highlighted on the left. Though, he hasn't discovered it yet, there's a spike spitter in-between him and the cube. The original path shows that the goblin was unaware of this threat:

(Lines are for debugging purposes only, and won't show up in the final game)

Now, the goblin has gotten closer and seen the threat. Goblins know they should void threats like this if they can, so he will find a new path that avoids the spike spitter:


The white and black lines show the A* algorithm at work. The more white the line, the higher the threat. The goblin chooses his path to avoid high threat. So you can see, the path finding algorithm didn't even try to get close to the spike spitter, since those threat values were getting so high, it wasn't worth exploring in that direction any further.

In this case, the perception range of the goblin was high enough to avoid the threat. If the goblin were to be surprised by an enemy, and came under attack, this same system can be used to find a flee path from the threat. The path doesn't need to be very long, just enough to get out of danger, so the path can be recalculated multiple times without a significant performance hit.

Additionally, this system is used for goblins to decide whether or not they should flee/avoid, engage in combat, or completely ignore a threat. The actual combat mechanics are what I'm working on next. My next blog post will be describing what I think an average game of AoG will play like. That topic was requested by a fan of the game. If you have something you'd like to read about AoG, post it in the comments. Thanks for your interest.

2 comments:

  1. Wow, And it would be a little more realistic if size and age are proportional (or inversely propotional) to its speed.

    ReplyDelete
    Replies
    1. There is a relationship between those three (size, age and speed). But the threat analysis system doesn't care how they're calculated, it just looks at the final values. The aging system and the body system will control the age and speed of a entity. I've put a little work into the aging system (which also affects the body). I plan on defining "grow bones" in the models that will be scaled depending on the age of the entity. For example, this would allow the spikes on a spike spitters body to get larger the more they age (thus increasing the threat). Thanks for reading and thanks for your input!

      Delete