Game Development Reference
In-Depth Information
null || playerAttack != null
. Then, add a
selector
node under the
constraint
node
that will handle the attack and chase logic. The multiple visual sensors behavior tree
should look like the following screenshot:
Remember the
selector
node will continue to run its children until one succeeds, so
first we will check for attack. If
playerAttack
has a value (that is, it is not null), we
will set
isAttacking
to true, and if not, set it to false. Add a
constraint
node under
the
selector
that checks for attacks and set its constraint to
playerAttack != null
. As
the
playerAttack
variable is not null, add an
expression
node to start attacking
with an expression value of
isAttacking
, which is equal to true.
Then, if
playerAttack
is null, we want the attack to stop, so add another expres-
sion with
isAttacking
, which is equal to false. The attack setup on our enemy be-
havior tree should look like the following screenshot:
If you run the demo now, when the player gets sensed by
AttackSensor
, the en-
emy will start attacking and stop when the player is out of range.