Time for action – Multiple personalities
Let's add a bit of code to our various Tick
functions so we can see exactly what happens as we change states. Normally, we wouldn't want to put logs in the Tick
function as it's called at every frame, but sometimes it's good for testing purposes.
First, we'll add a
Tick
function outside of the states so we can get a complete picture of what's going on.function Tick(float DeltaTime) { log("Non-State Tick"); }
Now let's add logs to our other
Tick
functions. First, theSeeking Tick
:function Tick(float DeltaTime) { local vector NewLocation; `log("Seeking Tick"); if(Enemy == none) GetEnemy(); if(Enemy != none) { NewLocation = Location; NewLocation += normal(Enemy.Location - Location) * MovementSpeed * DeltaTime; SetLocation(NewLocation); if(VSize(NewLocation - Enemy.Location) < AttackDistance) GoToState('Attacking'); } }
Next, the
Attacking Tick
:function Tick(float DeltaTime) { ``log("Attacking Tick"); if...