Update Enemy AI for Hearing Perception
This commit is contained in:
parent
b6fd4e0d75
commit
a86eb14b35
BIN
EndlessVendetta/Content/AI/Enemy/Basic/BB_BasicEnemy.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/AI/Enemy/Basic/BB_BasicEnemy.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/AI/Enemy/Basic/BT_BasicEnemy.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/AI/Enemy/Basic/BT_BasicEnemy.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
@ -7,6 +7,7 @@
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "EndlessVendetta/EndlessVendettaCharacter.h"
|
||||
#include "Perception/AIPerceptionComponent.h"
|
||||
#include "Perception/AISenseConfig_Hearing.h"
|
||||
#include "Perception/AISenseConfig_Sight.h"
|
||||
|
||||
|
||||
@ -53,9 +54,6 @@ void AAI_EnemyController::Tick(float DeltaTime)
|
||||
void AAI_EnemyController::SetupPerceptionSystem()
|
||||
{
|
||||
SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));
|
||||
if (IsValid(SightConfig))
|
||||
{
|
||||
SetPerceptionComponent(*CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component")));
|
||||
SightConfig->SightRadius = 2000.0f;
|
||||
SightConfig->LoseSightRadius = 2100.0f;
|
||||
SightConfig->PeripheralVisionAngleDegrees = 70.0f;
|
||||
@ -64,27 +62,45 @@ void AAI_EnemyController::SetupPerceptionSystem()
|
||||
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
|
||||
SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
|
||||
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
|
||||
|
||||
HearingConfig = CreateDefaultSubobject<UAISenseConfig_Hearing>(TEXT("Hearing Config"));
|
||||
HearingConfig->HearingRange = 2000.0f;
|
||||
HearingConfig->DetectionByAffiliation.bDetectEnemies = true;
|
||||
HearingConfig->DetectionByAffiliation.bDetectFriendlies = true;
|
||||
HearingConfig->DetectionByAffiliation.bDetectNeutrals = true;
|
||||
|
||||
if (!IsValid(SightConfig)) return;
|
||||
if (!IsValid(HearingConfig)) return;
|
||||
|
||||
SetPerceptionComponent(*CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component")));
|
||||
GetPerceptionComponent()->SetDominantSense(*SightConfig->GetSenseImplementation());
|
||||
GetPerceptionComponent()->OnTargetPerceptionUpdated.AddDynamic(this, &AAI_EnemyController::OnTargetPerceptionUpdated);
|
||||
GetPerceptionComponent()->ConfigureSense(*SightConfig);
|
||||
}
|
||||
GetPerceptionComponent()->ConfigureSense(*HearingConfig);
|
||||
}
|
||||
|
||||
void AAI_EnemyController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus const Stimulus)
|
||||
{
|
||||
if (AEndlessVendettaCharacter* const PlayerCharacter = Cast<AEndlessVendettaCharacter>(Actor))
|
||||
{
|
||||
if (Stimulus.WasSuccessfullySensed())
|
||||
if (Stimulus.WasSuccessfullySensed() && Stimulus.Type == SightConfig->GetSenseID())
|
||||
{
|
||||
GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor);
|
||||
GetBlackboardComponent()->SetValueAsVector("TargetLocation", Stimulus.StimulusLocation);
|
||||
GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", true);
|
||||
}
|
||||
else
|
||||
else if (!Stimulus.WasSuccessfullySensed() && Stimulus.Type == SightConfig->GetSenseID())
|
||||
{
|
||||
GetBlackboardComponent()->ClearValue("TargetActor");
|
||||
GetBlackboardComponent()->ClearValue("TargetLocation");
|
||||
GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", false);
|
||||
}
|
||||
|
||||
if (Stimulus.WasSuccessfullySensed() && Stimulus.Type == HearingConfig->GetSenseID())
|
||||
{
|
||||
GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor);
|
||||
GetBlackboardComponent()->SetValueAsVector("InvestigationLocation", Stimulus.StimulusLocation);
|
||||
GetBlackboardComponent()->SetValueAsBool("IsInvestigating", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
|
||||
private:
|
||||
class UAISenseConfig_Sight* SightConfig;
|
||||
class UAISenseConfig_Hearing* HearingConfig;
|
||||
void SetupPerceptionSystem();
|
||||
|
||||
UFUNCTION()
|
||||
|
@ -0,0 +1,27 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "BTTask_StopInvestigating.h"
|
||||
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "EndlessVendetta/AI/AI_EnemyController.h"
|
||||
#include "EndlessVendetta/AI/EnemyCharacter.h"
|
||||
|
||||
UBTTask_StopInvestigating::UBTTask_StopInvestigating()
|
||||
{
|
||||
NodeName = TEXT("Stop Investigating");
|
||||
}
|
||||
|
||||
EBTNodeResult::Type UBTTask_StopInvestigating::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
|
||||
{
|
||||
if (AAI_EnemyController* const EnemyController = Cast<AAI_EnemyController>(OwnerComp.GetOwner()))
|
||||
{
|
||||
if (UBlackboardComponent* const BlackboardComponent = OwnerComp.GetBlackboardComponent())
|
||||
{
|
||||
BlackboardComponent->ClearValue(GetSelectedBlackboardKey());
|
||||
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
|
||||
return EBTNodeResult::Succeeded;
|
||||
}
|
||||
}
|
||||
return EBTNodeResult::Failed;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BehaviorTree/Tasks/BTTask_BlackboardBase.h"
|
||||
#include "BTTask_StopInvestigating.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class ENDLESSVENDETTA_API UBTTask_StopInvestigating : public UBTTask_BlackboardBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UBTTask_StopInvestigating();
|
||||
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
|
||||
};
|
Loading…
Reference in New Issue
Block a user