-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTankAIController.cpp
52 lines (42 loc) · 1.12 KB
/
TankAIController.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Fill out your copyright notice in the Description page of Project Settings.
#include "BattleTank.h"
#include "TankAIController.h"
void ATankAIController::BeginPlay()
{
Super::BeginPlay();
auto PlayerTank = GetPlayerTank();
if (!PlayerTank)
{
UE_LOG(LogTemp, Warning, TEXT("AIController can't find player tank"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("AIController found player: %s"), *(PlayerTank->GetName()));
}
}
// Called every frame
void ATankAIController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (GetPlayerTank())
{
// TODO Move towards the player
// Aim towards the player
GetAimingComponent()->AimAt(GetPlayerTank()->GetActorLocation());
// Fire if readyk
}
}
ATank* ATankAIController::GetControlledTank() const
{
return Cast<ATank>(GetPawn());
}
UTankAimingComponent* ATankAIController::GetAimingComponent() const
{
return Cast<UTankAimingComponent>(GetPawn());
}
ATank* ATankAIController::GetPlayerTank() const
{
auto PlayerPawn = GetWorld()->GetFirstPlayerController()->GetPawn();
if (!PlayerPawn) { return nullptr; } // Note the !, very important
return Cast<ATank>(PlayerPawn);
}