-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIControllerBase.cpp
More file actions
94 lines (79 loc) · 2.96 KB
/
AIControllerBase.cpp
File metadata and controls
94 lines (79 loc) · 2.96 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Fill out your copyright notice in the Description page of Project Settings.
#include "AIControllerBase.h"
#include "DrawDebugHelpers.h"
#include "Kismet/GameplayStatics.h"
AAIControllerBase::AAIControllerBase() : AAIController()
{
SetGenericTeamId(FGenericTeamId(5));
}
ETeamAttitude::Type AAIControllerBase::GetTeamAttitudeTowards(const AActor& Other) const
{
if (const APawn* OtherPawn = Cast<APawn>(&Other)) {
if (const IGenericTeamAgentInterface* TeamAgent = Cast<IGenericTeamAgentInterface>(OtherPawn->GetController()))
{
return Super::GetTeamAttitudeTowards(*OtherPawn->GetController());
}
}
return ETeamAttitude::Neutral;
}
bool AAIControllerBase::CalculateDetection(ACharacter* PawnDetected, ACharacter* Detector)
{
UWorld* World = GetWorld();
if (World == nullptr) return false;
if (Detector != nullptr && PawnDetected != nullptr)
{
FVector TraceStart = Detector->GetActorLocation();
UMeshComponent* DetectorMesh = Detector->GetMesh();
UMeshComponent* PawnDetectedMesh = PawnDetected->GetMesh();
if(!ensure(DetectorMesh != nullptr && PawnDetectedMesh != nullptr)) return false;
if (DetectorMesh != nullptr)
{
TraceStart = DetectorMesh->GetSocketLocation(this->DetectorTraceStartBone);
}
if (BonesDetection.Num() != 0)
{
TArray<TEnumAsByte<EObjectTypeQuery>> TraceObjectTypes;
TraceObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECollisionChannel::ECC_Pawn));
FCollisionObjectQueryParams const DetectionTraceParams = FCollisionObjectQueryParams(TraceObjectTypes);
FHitResult HitResult;
int LinesHit = 0;
for (auto const Bone : BonesDetection)
{
FVector BoneLocation = PawnDetectedMesh->GetSocketLocation(Bone);
FCollisionQueryParams TraceParams;
TraceParams.AddIgnoredActor(Detector);
World->LineTraceSingleByObjectType(HitResult,TraceStart,BoneLocation,DetectionTraceParams,TraceParams);
//World->LineTraceSingleByChannel(HitResult,TraceStart,BoneLocation,ECC_Visibility,TraceParams);
if(bDetectionDebug)
{
DrawDebugLine(World,TraceStart,BoneLocation,FColor::Magenta,true,-1.f,0,1.5f);
}
if(HitResult.GetActor() == PawnDetected)
{
LinesHit++;
}
}
if (LinesHit >= DetectionLineSuccessThreshold)
{
return true;
}
}
}
return false;
}
void AAIControllerBase::CalculateAwarenessLevelOnDetection(AActor* PawnDetected, AActor* Detector)
{
float const Distance = FVector::Distance(PawnDetected->GetActorLocation(), Detector->GetActorLocation());
if (Distance <= AwarenessThresholds.FindRef(EAwarenessThreshold::Low))
{
this->Awareness = AwarenessInitialValues.Low;
}
else if (Distance <= AwarenessThresholds.FindRef(EAwarenessThreshold::Medium))
{
this->Awareness = this->AwarenessInitialValues.Medium;
}
else if ( Distance <= AwarenessThresholds.FindRef(EAwarenessThreshold::High) )
{
Awareness = this->AwarenessInitialValues.High;
}
}