I'm trying to make a very basic turret that fires at an enemy as they approach. I got it to attack the first enemy that approaches, but when it destroys the target it continues to fire in the same direction.
What am I doing wrong?
AwesomeTurret.uc
AwesomeTurret_Rocket.ucCode:class AwesomeTurret extends AwesomeActor; var actor Enemy; var float AttackDistance; var bool bAttacking; function GetEnemyAI() { local AwesomeEnemy AE; foreach DynamicActors(class'AwesomeEnemy', AE) { if(AE != none) Enemy = AE; } } auto state Seeking { function Tick(float DeltaTime) { if(Enemy == none) `log("Turret is Seeking!!!!!!!!!!!!!!!"); GetEnemyAI(); if(Enemy != none) GoToState('Attacking'); else GoToState('Seeking'); } } state Attacking { } defaultproperties { AttackDistance=45.0 Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment bEnabled=True End Object Components.Add(MyLightEnvironment) Begin Object Class=StaticMeshComponent Name=TurretMesh StaticMesh=StaticMesh'Pickups.Health_Large.Mesh.S_Pickups_Base_Health_Large' LightEnvironment=MylightEnvironment End Object Components.Add(TurretMesh) Begin Object Class=CylinderComponent Name=CollisionCylinder CollisionRadius=15.0 CollisionHeight=15.0 BlockNonZeroExtent=True BlockZeroExtent=True BlockActors=True CollideActors=True End Object CollisionComponent=CollisionCylinder Components.Add(CollisionCylinder) }
Code:class AwesomeTurret_Rocket extends AwesomeTurret placeable; var actor CurrentEnemy; auto state Seeking { function Seeking() { CurrentEnemy = Enemy; } } state Attacking { function BeginState(name PreviousStateName) { SetTimer(1, false, 'Attack'); } function Attack() { local UTProj_Rocket MyRocket; if(CurrentEnemy == none) GetEnemyAI(); if(CurrentEnemy != none) bAttacking=True; MyRocket = spawn(class'UTProj_Rocket', self,, Location); MyRocket.Init(normal(Enemy.Location - Location)); SetTimer(2, false, 'Seeking'); } } defaultproperties { AttackDistance=45.0 }



Reply With Quote



Bookmarks