Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #pragma once
  2.  
  3.  
  4. #include "TankAIController.h"
  5. #include "Engine/World.h"
  6. #include "TankAimingComponent.h"
  7. #include "BattleTank.h"
  8.  
  9.  
  10. void ATankAIController::BeginPlay()
  11. {
  12. Super::BeginPlay();
  13. }
  14.  
  15. // Called every frame
  16. void ATankAIController::Tick(float DeltaTime)
  17. {
  18. Super::Tick(DeltaTime);
  19.  
  20. auto PlayerTank = GetWorld()->GetFirstPlayerController()->GetPawn();
  21. auto ControlledTank = GetPawn();
  22.  
  23. if (!ensure(PlayerTank && ControlledTank)) { return; }
  24.  
  25. // Move towards the player
  26. MoveToActor(PlayerTank, AcceptanceRadius); // TODO check radius is in cm
  27.  
  28. // Aim towards the player
  29. auto AimingComponent = ControlledTank->FindComponentByClass<UTankAimingComponent>();
  30. AimingComponent->AimAt(PlayerTank->GetActorLocation());
  31.  
  32. if (AimingComponent->GetFiringState() == EFiringState::Locked)
  33. {
  34. AimingComponent->Fire();
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement