Time for action – EndState
Let's use EndState
to stop the enemies from moving for a second after they've attacked us. That will give us a little bit of time to get away from them, so they're not constantly swarming around us.
First, let's add a
bool
to the top of our class:var bool bAttacking;
We'll use this variable to keep the enemy from moving during an attack.
This will only really apply to the
Seeking
state, we don't want to stop the enemy from fleeing just because they were attacking us. Let's change theTick
function in theSeeking
state:function Tick(float DeltaTime) { local vector NewLocation; if(bAttacking) return; 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'); } }
Now if
bAttacking
istrue
, then none of the movement code will...