The Attack branch does the actual attacking of the target:
The Attack branch uses a Self conditional abort to reevaluate the Is Alive conditional task every tick. This will stop the agent from attacking if the target is no longer alive. If the target is alive three branches run at the same time:
- The branch that moves the agent into attack or cover position.
- The branch that determines the best weapon.
- The branch that does the actual attack.
Let’s take a look at these branches one at a time. The first branch is the movement branch:
A Selector is used so one of two branches will run: either a cover branch or a regular attack movement branch. The Find Cover task will return Success if the agent is near a Cover Point and should move into cover. There is a chance that the agent is already in cover from a lower priority task so the Is Ability Active task will return Success if the Cover ability is active. If the Cover ability is not active then there’s a chance that the agent will not take cover even though the Find Cover task returns Success. This happens with the Random Probability task. If either the Is Ability Active or the Random Probability task returns Success then the Cover branch will run.
If the cover branch should not run then the agent will run the Attack Movement task. Before the Attack Movement task is run the Reset task is used to reset the cover variables. The Start Stop Ability task will also ensure the agent is aiming at the target. The Attack Movement task will move the agent into attacking position. While the agent is moving into position the Determine Weapon branch also runs:
The Determine Weapon branch is parented by a Repeater to allow the agent to determine the best weapon for the situation every tick. The Determine Weapon task will set which Item Set should be equipped and the Start Equip Unequip task will equip that item. In addition to determining which Item should be equipped, the agent is also doing the actual attack:
Similar to the Determine Weapon branch, the attack sub-branch will use a Repeater to continuously try to attack. Before the agent can actually attack though with the Attack task it must first check the Can Attack bool variable. This variable is set by the Cover branch and will set it to false if the agent is moving in or is between cover positions.
The Parallel task is used so the agent can attack or throw a grenade independently of one another. On the left side of the parallel task the agent will perform the attack with the equipped weapon:
The Return Success task ensures the Parallel task will keep on running even if the attack fails. A Selector is then placed to allow the agent to attack an explosive barrel if the target is nearby. This is checked with the Is Target Near Explosive task. If the target is near an explosive then the Attack task will fire at the explosive, otherwise the Attack task will fire at the target.
The right branch under the Parallel task will throw a grenade if it should be thrown. There are many conditions which would prevent a grenade from being thrown so the grenade is not thrown more often than it is thrown. The Try Throw Grenade task is parented to the Return Success task to keep the branch active.