Time for action – Switching states
Three states, Seeking
, Attacking
, and Frozen
. The first thing we need to do is tell our actor which state to start in.
To do that, we'll simply add the
auto
keyword to the beginning of ourSeeking
state:auto state Seeking
Only one state can be declared with the auto
keyword, and this state is the default state for that actor. We want ours to do the same thing it did before, automatically start moving toward the player when it spawns.
Now that we're in the
Seeking
state, we need to tell the actor when to move into theAttacking
state. We'll do this in theTick
function by comparing the distance between the actor and its enemy:function Tick(float DeltaTime)
{ local vector NewLocation; 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...