Last week we added a new complex behavior to our arsenal called wandering. It's pretty cool, and can be used along with other behaviors to make AI's seem more random than they would otherwise be with just seeking or fleeing behavior alone. Go ahead and check that post out here if you haven't read it already.
Now that we have that little bit of business out of the way, ahem: BEHOLD! THE GREAT TOPIC AWAITS:
Agent Movement/Steering: Pursuing and Evading Behaviors
You can, and should, read the original article here.
Agents that pursue or evade are more responsive and accurate at catching a target than agents that seek or flee. This is because they steer towards a point that is slightly in front of their target, which allows for them to be predictive of where the target with be in the future. As you might remember from your days playing tag at recess, this is pretty much what real children do automatically. They look to where the target will be in the future, then they either seek or flee that future position.
Like wandering, pursuing and evading behaviors make a few calculations before applying the simple seek or flee movement. In this case, they calculate where the target agent will be after T game updates. The value for T can either be fixed or fluid, but it is better to be fluid, as I'll explain in a bit. To get this future position, simply add the target position to the target velocity multiplied by T.
A pursuing agent will seek towards this future position, and an evading agent will flee from this future position. It's a simple yet effective method of creating responsive agent movement towards a moving target. I would definitely use this for agents that need to be an annoyance in either direction because players would usually like to feel that the AI of a game is effective and challenging.
If an agent uses a fixed T value, then it can be made even more effective by making T dependent on the distance between the target position and the agent's position. The agent does not need to predict where the target will be when they are close, so as the distance between the two decreases, the number of updates T should also decrease.
This is something that I wish our team had thought about when programming Dot Wars, specifically for the game-type Survival. True, the Suicide Dot's AI is already pretty effective, but adding a pursuing behavior like this to them would have helped convince the player that they were under more of a threat.
Go ahead and take a look at the Github that has the new updated code for pursuit and evasion. You may notice that if you spawn a pursue agent and an evade agent, they both move in exactly the same way and never catch each other. Do not be alarmed by this; technically, that means that the base code is working just as it should be!
