void ATankAIController::Tick(float deltaTime) { Super::Tick(deltaTime); auto playerTank = GetWorld()->GetFirstPlayerController()->GetPawn(); if (ensure(playerTank && GetPawn())) { MoveToActor(playerTank, acceptanceRadius); auto aimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>(); aimingComponent->AimAt(playerTank->GetActorLocation()); if(aimingComponent->GetFiringStatus() == EFiringStatus::Locked) aimingComponent->Fire(); } }
void ATankAIController::Tick(float DeltaTime){ Super::Tick(DeltaTime); auto PlayerTank = GetWorld()->GetFirstPlayerController()->GetPawn(); auto ControlledTank = GetPawn(); if(!ensure(PlayerTank && ControlledTank)){return ; } //move towards player MoveToActor(PlayerTank, AcceptanceRadius); //aim towards the player auto AimingComponent = ControlledTank->FindComponentByClass<UTankAimingComponent>(); AimingComponent->AimAt(PlayerTank->GetActorLocation()); //Fire if ready if(AimingComponent->GetFiringStatus() == EFiringStatus::Locked) { AimingComponent->Fire(); } }