Game Development Reference
In-Depth Information
Note
Our attack behavior here is very simple; we are just flashing the ship. However,
there's no reason why you couldn't add additional attack nodes and states to
make the behavior more realistic.
Finally, we need to have the enemy chase the player if it is not attacking, so add a
custom node called
Chase
to the bottom of the selector. Create a
Chase
script for it
and set the
Chase
code to the following:
This code first finds the
player
GameObject and then just moves to the player's
position. This is unlike the code in the demos in
Chapter 7
,
Adaptation
, where we did
a check to stop moving if the character gets very close to the moving target. When
the character gets close to the target, it will stop moving and start attacking, so we
don't need checks. If you run the demo now, the enemy will chase the player and
start attacking: