-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHunterCharacter.cpp
61 lines (49 loc) · 1.76 KB
/
HunterCharacter.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
53
54
55
56
57
58
59
60
61
// Fill out your copyright notice in the Description page of Project Settings.
#include "RunForLife.h"
#include "HunterCharacter.h"
#include "HunterAIController.h"
#include "RunForLifeCharacter.h"
#include "PreyCharacter.h"
// AI module
#include "Perception/PawnSensingComponent.h"
// Sets default values
AHunterCharacter::AHunterCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// Set vision angle smaller than other characters
PawnSensingComp->SetPeripheralVisionAngle(60.0f);
// Set run speed faster than other characters
RunSpeed = 700.0f;
// Set as unlimited stamina
ConsumeStaminaRate = 0.0f;
}
// Called when the game starts or when spawned
void AHunterCharacter::BeginPlay()
{
Super::BeginPlay();
// Add delagates to the sensing component
if (PawnSensingComp)
{
PawnSensingComp->OnSeePawn.AddDynamic(this, &AHunterCharacter::OnSeePawn);
PawnSensingComp->OnHearNoise.AddDynamic(this, &AHunterCharacter::OnHearNoise);
}
}
// Called when seeing a pawn
void AHunterCharacter::OnSeePawn(APawn* Pawn)
{
AHunterAIController* HunterAIController = Cast<AHunterAIController>(GetController());
ARunForLifeCharacter* RunForLifeCharacter = Cast<ARunForLifeCharacter>(Pawn);
APreyCharacter* PreyCharacter = Cast<APreyCharacter>(Pawn);
if (HunterAIController && (RunForLifeCharacter || PreyCharacter))
{
HunterAIController->SetPreyLocation(Pawn);
}
}
// Called when hearing noise
void AHunterCharacter::OnHearNoise(APawn* PawnInstigator, const FVector& Location, float Volume)
{
AHunterAIController* HunterAIController = Cast<AHunterAIController>(GetController());
if (HunterAIController && PawnInstigator != this)
{
HunterAIController->SetNoiseLocation(Location);
}
}