Damaged

The next highest priority branch after the Near Grenade branch is the Damaged branch:

The Damaged branch makes use of conditional aborts similar to the Near Grenade branch. This time though the top Sequence task uses a Lower Priority abort type instead of a Both abort type. The reason for this is because we don’t want to stop any task within the Damaged branch from running if the conditional task changes status. The Lower Priority conditional abort will reevaluate Is Damaged every tick to determine if the agent has taken any damage. If the task returns Success then the conditional abort will trigger assuming any lower priority branch is running. This basically means that the conditional abort will trigger if any branch besides the Near Grenade branch is running.

The first task to run is the Reset task similar to the Near Grenade branch. We want to make sure almost all of the variables start fresh in case the conditional abort triggered the branch to run. Following the Reset task we have a Selector which will first try to run the left child branch and then if that returns Failure it’ll try to run the right child branch. First we’ll take a look at the Flee branch:

The first task within the left child branch is the Should Flee task. This task decides if the agent should flee from the attacker: if it returns Success then the agent should flee. A Random Probability task is then added to the right of Should Flee to give the agent a chance to run the right branch even though Should Flee said that the agent should flee. If both conditional tasks return Success then the Flee task will run which will move the agent away from the attacking target.

If the agent does not flee than the right branch runs:

The goal of this branch is to determine if the agent should switch its target to the attacking target. The first task that runs is the Check For Target Switch conditional task. This task will evaluate if the agent should switch from the current target to the attacker. If Check For Target Switch returns Success then a small branch will run which determines if the current target should be added to the Ignore Targets variable.

The Ignore Targets variable is a set which keeps a list of targets that should be ignored. This is useful to prevent the agent from quickly switching back and forth between targets. For example, if the agent is originally attacking Character 1 and then Character 2 starts to also attack the agent. The Damaged branch may switch the target to Character 2 but in the meantime Character 1 is still attacking. At this point Character 1 would have been added to the Ignore Targets set so the agent will not switch back to Character 1.

The Compare Shared GameObject compares the Target variable to null. If the target is null then the task will return Success but we want to know if the target is not null so an Inverter has been parented to the task. If the target is not null then the Add Target To GameObject Set task is run.

After the target was possibly added to the Ignore Target set the next task will get the position of the target and following that the Search variable will be set to true. This allows the agent to start looking for the attacker that hit the agent. The last task that is run is the Reset task which will reset the Target back to null since no targets are currently within sight.