-
Notifications
You must be signed in to change notification settings - Fork 2
/
PreyCharacter.cpp
52 lines (41 loc) · 1.37 KB
/
PreyCharacter.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 "RunForLife.h"
#include "PreyCharacter.h"
#include "PreyAIController.h"
#include "HunterCharacter.h"
// AI module
#include "Perception/PawnSensingComponent.h"
// Sets default values
APreyCharacter::APreyCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
}
// Called when the game starts or when spawned
void APreyCharacter::BeginPlay()
{
Super::BeginPlay();
// Add delagates to the sensing component
if (PawnSensingComp)
{
PawnSensingComp->OnSeePawn.AddDynamic(this, &APreyCharacter::OnSeePawn);
PawnSensingComp->OnHearNoise.AddDynamic(this, &APreyCharacter::OnHearNoise);
}
}
// Called when seeing a pawn
void APreyCharacter::OnSeePawn(APawn* Pawn)
{
APreyAIController* PreyAIController = Cast<APreyAIController>(GetController());
AHunterCharacter* HunterCharacter = Cast<AHunterCharacter>(Pawn);
if (PreyAIController && HunterCharacter)
{
PreyAIController->SetHunterLocation(Pawn);
}
}
// Called when hearing noise
void APreyCharacter::OnHearNoise(APawn* PawnInstigator, const FVector& Location, float Volume)
{
APreyAIController* PreyAIController = Cast<APreyAIController>(GetController());
if (PreyAIController && PawnInstigator != this)
{
PreyAIController->SetNoiseLocation(Location);
}
}