I am working on a simple project that will serve as pillar to future ones.
My problem is. When I move from my "Seeking" state to my "attacking" state, I check if I am within the enemies fire range. If I am, it shoots at me. To do this I placed a call to the function 'FireRocket' inside the ' if(Enemy != none && VSize(Location - Enemy.Location) < AttackDistance)' statement. This works perfectly but, as expected, a tone of missiles are fired per second (since this code is inside a 'tick function). To avoid this, I tried to use SetTimer (SetTimer(FireInterval, true, 'FireRocket');) and this is when my problem came up.
Now, the timer only starts counting when I move OUT of range of the enemy and he does indeed fire, but again, only when I am OUTSIDE of its range. When I come back to its range parameters, he stops firing at me...
The problem is on the "ATTACKING" state.
Thank you in advance for your help.
class AwesomeRangedBoss extends AwesomeEnemy
placeable;
var float FireInterval;
////EVENTS////
auto state Seeking
{
function Tick(float Deltatime)
{
local vector NewLocation;
if(Enemy == none)
{
GetEnemy();
}
else if(VSize(Location - Enemy.Location) < FollowDistance)
{
NewLocation = Location;
NewLocation += normal(Enemy.Location - Location) * MovementSpeed * DeltaTime;
SetLocation(NewLocation);
if(VSize(NewLocation - Enemy.Location) < AttackDistance)
{
GoToState('Attacking');
}
}
}
}
state Attacking
{
function Tick(float Deltatime)
{
if(Enemy == none)
{
GetEnemy();
}
if(Enemy != none && VSize(Location - Enemy.Location) < AttackDistance)
{
//SetTimer(FireInterval, true, 'FireRocket');
//FireRocket();
}
if(VSize(Location - Enemy.Location) > AttackDistance)
{
GoToState('Seeking');
}
}
}
/////////////////////////
function FireRocket()
{
local UTProj_Rocket MyRocket;
`log("BOOM!");
MyRocket = spawn(class'UTProj_Rocket', self,, Location);
MyRocket.Init(normal(Enemy.Location - Location));
MyMesh.SetMaterial(0, AttackingMat);
SetTimer(1, false, 'EndAttack');
}
event TakeDamage(int DamageAmount, Controller EventInstigator,
vector HitLocation, vector Momentum, class<DamageType> DamageType,
optional TraceHitInfo HitInfo, optional Actor DamageCauser)
{
Health--;
if(Health == 0 && EventInstigator != none &&
EventInstigator.PlayerReplicationInfo != none)
{
WorldInfo.Game.ScoreObjective(EventInstigator.PlayerReplicationInfo, 1);
Destroy();
}
}
defaultproperties
{
BumpDamage = 15.0
MovementSpeed = 256
FollowDistance = 1512
AttackDistance = 1024
Health = 5
FireInterval = 1
Begin Object Name=EnemyMesh
Scale3D=(X=1.0, Y=1.0, Z=2.0)
End Object
Begin Object Name=CollisionCylinder
CollisionRadius=128.0
CollisionHeight=256.0
End Object
}