Cover

The Cover branch is used in two locations: the first is within the Attack branch and the other in an independent branch reevanuated with a Lower Priority abort type. The Cover branch looks like:

When an agent is in cover the Cover Point can specify a linked Cover Point which allows the agent to move between cover positions. The Repeater at the top of the Cover branch will do the actual switch between cover positions. Just below the Repeater is a Sequence task which has the Self abort type. This allows the agent to get out of cover if either of the first two conditions return Success.

The Is Target Within Distance task is the first condition that is checked for the Cover branch. It is parented by an Inverter so the agent stops taking cover if the target comes too close to the agent. The second conditional task is the Is Ammo Low task. If the agent is low on ammo then they should get out of cover.

Assuming these two conditional tasks return Failure (and thus return Success with the Inverter), the Set Bool task will run which sets the Can Attack bool to false. This prevents the agent from attacking while moving into cover. The Start Cover task will then run to move the agent to the Cover Point.

As mentioned at the start of this section, the Cover branch can be called from two different locations. The first is within the Attack branch and the second is in a lower priority branch just to the left of the branch which searches for the target. The agent may be taking cover in hopes that a target comes within their sights. If a target does come within sight the Can See Target branch will abort the current Cover branch and start running the Cover branch that is within the Attack branch. If the agent is already in cover the Start Cover task will move them to a new cover location only if the Find Cover task returned a new location. After the agent is in cover the Set Bool task will reset the Can Attack variable so the agent can attack.

As soon as the agent is in cover they should aim in and out of cover to be able to attack the target. In addition, a separate timer should start to determine when the agent should change cover points. The last branch accomplishes both of those goals:

The Parallel Complete task is similar to the Parallel Selector task except it will stop as soon as the child returns Success or Failure. The Parallel Selector only stops if the child returns Success. The purpose of this task is to stop running both children when either child finishes executing. Cover Movement will decide when the agent should take cover versus aim out of cover and attack the target. If the target is no longer in sight then Cover Movement will return Failure. The other branch will wait a specified amount of time before selecting a new cover point with Find Cover. Find Cover will return Success if a new cover point has been found. In both of these cases the other branch should stop running if one of the branches returns a Success or Failure status.