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 "BehaviorTree/BlackboardComponent.h"
|
||||||
#include "EndlessVendetta/EndlessVendettaCharacter.h"
|
#include "EndlessVendetta/EndlessVendettaCharacter.h"
|
||||||
#include "Perception/AIPerceptionComponent.h"
|
#include "Perception/AIPerceptionComponent.h"
|
||||||
|
#include "Perception/AISenseConfig_Hearing.h"
|
||||||
#include "Perception/AISenseConfig_Sight.h"
|
#include "Perception/AISenseConfig_Sight.h"
|
||||||
|
|
||||||
|
|
||||||
@ -53,38 +54,53 @@ void AAI_EnemyController::Tick(float DeltaTime)
|
|||||||
void AAI_EnemyController::SetupPerceptionSystem()
|
void AAI_EnemyController::SetupPerceptionSystem()
|
||||||
{
|
{
|
||||||
SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));
|
SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));
|
||||||
if (IsValid(SightConfig))
|
SightConfig->SightRadius = 2000.0f;
|
||||||
{
|
SightConfig->LoseSightRadius = 2100.0f;
|
||||||
SetPerceptionComponent(*CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component")));
|
SightConfig->PeripheralVisionAngleDegrees = 70.0f;
|
||||||
SightConfig->SightRadius = 2000.0f;
|
SightConfig->SetMaxAge(20.0f);
|
||||||
SightConfig->LoseSightRadius = 2100.0f;
|
SightConfig->AutoSuccessRangeFromLastSeenLocation = 520.0f;
|
||||||
SightConfig->PeripheralVisionAngleDegrees = 70.0f;
|
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
|
||||||
SightConfig->SetMaxAge(20.0f);
|
SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
|
||||||
SightConfig->AutoSuccessRangeFromLastSeenLocation = 520.0f;
|
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
|
||||||
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
|
|
||||||
SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
|
HearingConfig = CreateDefaultSubobject<UAISenseConfig_Hearing>(TEXT("Hearing Config"));
|
||||||
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
|
HearingConfig->HearingRange = 2000.0f;
|
||||||
GetPerceptionComponent()->SetDominantSense(*SightConfig->GetSenseImplementation());
|
HearingConfig->DetectionByAffiliation.bDetectEnemies = true;
|
||||||
GetPerceptionComponent()->OnTargetPerceptionUpdated.AddDynamic(this, &AAI_EnemyController::OnTargetPerceptionUpdated);
|
HearingConfig->DetectionByAffiliation.bDetectFriendlies = true;
|
||||||
GetPerceptionComponent()->ConfigureSense(*SightConfig);
|
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)
|
void AAI_EnemyController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus const Stimulus)
|
||||||
{
|
{
|
||||||
if (AEndlessVendettaCharacter* const PlayerCharacter = Cast<AEndlessVendettaCharacter>(Actor))
|
if (AEndlessVendettaCharacter* const PlayerCharacter = Cast<AEndlessVendettaCharacter>(Actor))
|
||||||
{
|
{
|
||||||
if (Stimulus.WasSuccessfullySensed())
|
if (Stimulus.WasSuccessfullySensed() && Stimulus.Type == SightConfig->GetSenseID())
|
||||||
{
|
{
|
||||||
GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor);
|
GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor);
|
||||||
GetBlackboardComponent()->SetValueAsVector("TargetLocation", Stimulus.StimulusLocation);
|
GetBlackboardComponent()->SetValueAsVector("TargetLocation", Stimulus.StimulusLocation);
|
||||||
GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", true);
|
GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", true);
|
||||||
}
|
}
|
||||||
else
|
else if (!Stimulus.WasSuccessfullySensed() && Stimulus.Type == SightConfig->GetSenseID())
|
||||||
{
|
{
|
||||||
GetBlackboardComponent()->ClearValue("TargetActor");
|
GetBlackboardComponent()->ClearValue("TargetActor");
|
||||||
GetBlackboardComponent()->ClearValue("TargetLocation");
|
GetBlackboardComponent()->ClearValue("TargetLocation");
|
||||||
GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", false);
|
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:
|
private:
|
||||||
class UAISenseConfig_Sight* SightConfig;
|
class UAISenseConfig_Sight* SightConfig;
|
||||||
|
class UAISenseConfig_Hearing* HearingConfig;
|
||||||
void SetupPerceptionSystem();
|
void SetupPerceptionSystem();
|
||||||
|
|
||||||
UFUNCTION()
|
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