In this recipe, we will create a control that is going to steer an AI character. Using Control
to do this is beneficial since it can add the AI functionality and be used together with other Controls
in the game. We can use GameCharacterControl
from Chapter 2, Cameras and Game Controls for both the player and AI characters by adding AIControl
to its spatial. To get a quick and visual result, we'll apply it to the bullet-based BetterCharacterControl
class in this recipe.
We need to perform the following steps to get a basic, but functional attacking (or following) AI:
We begin by creating a new class called
AIControl
, extendingAbstractControl
. The core of the recipe will be based around an enum (enumeration) calledstate
. For now it only needs two values:Idle
andFollow
.Add fields for
BetterCharacterControl
, calledphysicsCharacter
, Booleansforward
andbackwards
, aVector3f
field forwalkDirection
, and another forviewDirection
. If it's...