我正在开发一个简单的项目,作为未来项目的支柱。
我的问题是。当我从“寻找”状态移动到我的“攻击”状态时,我会检查我是否在敌人射程范围内。如果我是,它会射击我。为此,我在'if(Enemy!= none&& VSize(Location - Enemy.Location)< AttackDistance)'语句中调用了函数'FireRocket'。这完美地工作,但正如预期的那样,每秒发射一次导弹音(因为这个代码在'tick函数内)。为了避免这种情况,我尝试使用SetTimer(SetTimer(FireInterval,true,'FireRocket');)这就是我的问题出现的时候。
现在,计时器只在我移出敌人射程时才开始计数,但他确实开火了,但是只有在我超出其范围时才会开始计时。当我回到它的范围参数时,他停止向我射击......
问题出在“攻击”状态。
提前感谢您的帮助。
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
}
答案 0 :(得分:1)
解决!这是编辑过的代码。现在,射击以1秒的间隔正确射击。
state Attacking
{
function Tick(float Deltatime)
{
//HasFired = true;
if(Enemy == none)
{
GetEnemy();
}
if(Enemy != none && VSize(Location - Enemy.Location) < AttackDistance)
{
ShootRocket();
}
if(VSize(Location - Enemy.Location) > AttackDistance)
{
GoToState('Seeking');
}
}
}
/////////////////////////
function ShootRocket()
{
local UTProj_Rocket MyRocket;
if(Enemy != none && VSize(Location - Enemy.Location) < AttackDistance && HasFired == false)
{
`log("BOOM!");
MyRocket = spawn(class'UTProj_Rocket', self,, Location);
MyRocket.Init(normal(Enemy.Location - Location));
MyMesh.SetMaterial(0, AttackingMat);
SetTimer(1, false, 'EndAttack');
HasFired = true;
if(HasFired == true)
{
SetTimer(FireInterval, false, 'IsAttacking');
}
}
}
function IsAttacking()
{
HasFired = false;
GoToState('Attacking');
}