Merge branch 'Enemy-AI' into dev

# Conflicts:
#	EndlessVendetta/Content/Gadgets/ReconGadgets/VisionLink/VisionLinkViewPortBG.uasset
#	EndlessVendetta/Content/Gadgets/ReconGadgets/VisionLink/WatchFaceBGImage.uasset
This commit is contained in:
Philip W 2023-10-04 02:31:56 +01:00
commit 8fc80f9b31
22 changed files with 248 additions and 17 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
EndlessVendetta/Content/AI/EQSB_Enemy.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
EndlessVendetta/Content/AI/EQSB_Player.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
EndlessVendetta/Content/AI/EQS_Test.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,85 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AI_CompanionController.h"
#include "AI_EnemyController.h"
#include "CompanionCharacter.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "Perception/AIPerceptionComponent.h"
#include "Perception/AISenseConfig_Sight.h"
AAI_CompanionController::AAI_CompanionController(FObjectInitializer const& ObjectInitializer)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
AAIController::SetGenericTeamId(FGenericTeamId(0));
SetupPerceptionSystem();
}
// Called when the game starts or when spawned
void AAI_CompanionController::BeginPlay()
{
Super::BeginPlay();
}
void AAI_CompanionController::OnPossess(APawn* InPawn)
{
Super::OnPossess(InPawn);
if (const ACompanionCharacter* CompanionCharacter = Cast<ACompanionCharacter>(InPawn))
{
if (UBehaviorTree* const BehaviorTree = CompanionCharacter->GetBehaviorTree())
{
UBlackboardComponent* TempBlackboardPtr;
UseBlackboard(BehaviorTree->BlackboardAsset, TempBlackboardPtr);
Blackboard = TempBlackboardPtr;
RunBehaviorTree(BehaviorTree);
}
}
}
// Called every frame
void AAI_CompanionController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AAI_CompanionController::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;
SightConfig->SetMaxAge(20.0f);
SightConfig->AutoSuccessRangeFromLastSeenLocation = 520.0f;
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
GetPerceptionComponent()->SetDominantSense(*SightConfig->GetSenseImplementation());
GetPerceptionComponent()->OnTargetPerceptionUpdated.AddDynamic(this, &AAI_CompanionController::OnTargetPerceptionUpdated);
GetPerceptionComponent()->ConfigureSense(*SightConfig);
}
}
void AAI_CompanionController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus const Stimulus)
{
if (AEndlessVendettaCharacter* const PlayerCharacter = Cast<AEndlessVendettaCharacter>(Actor))
{
// if (Stimulus.WasSuccessfullySensed())
// {
// GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor);
// GetBlackboardComponent()->SetValueAsVector("TargetLocation", Stimulus.StimulusLocation);
// GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", true);
// }
// else
// {
// GetBlackboardComponent()->ClearValue("TargetActor");
// GetBlackboardComponent()->ClearValue("TargetLocation");
// GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", false);
// }
}
}

View File

@ -0,0 +1,36 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "AI_CompanionController.generated.h"
struct FAIStimulus;
UCLASS()
class ENDLESSVENDETTA_API AAI_CompanionController : public AAIController
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
explicit AAI_CompanionController(FObjectInitializer const& ObjectInitializer);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
virtual void OnPossess(APawn* InPawn) override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
private:
class UAISenseConfig_Sight* SightConfig;
void SetupPerceptionSystem();
UFUNCTION()
void OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus const Stimulus);
};

View File

@ -15,7 +15,7 @@ AAI_EnemyController::AAI_EnemyController(FObjectInitializer const& ObjectInitial
{ {
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
AAIController::SetGenericTeamId(FGenericTeamId(1));
SetupPerceptionSystem(); SetupPerceptionSystem();
} }

View File

@ -19,6 +19,7 @@ EBTNodeResult::Type UBTTask_AttackPlayer::ExecuteTask(UBehaviorTreeComponent& Ow
FVector const Origin = AIController->GetPawn()->GetActorLocation(); FVector const Origin = AIController->GetPawn()->GetActorLocation();
FVector const PlayerLocation = Blackboard->GetValueAsVector("TargetLocation"); FVector const PlayerLocation = Blackboard->GetValueAsVector("TargetLocation");
DrawDebugLine(GetWorld(), Origin, PlayerLocation, FColor::Green, false, 1.f, 0, 1.f); DrawDebugLine(GetWorld(), Origin, PlayerLocation, FColor::Green, false, 1.f, 0, 1.f);
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded); FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
return EBTNodeResult::Succeeded; return EBTNodeResult::Succeeded;
} }

View File

@ -0,0 +1,50 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "CompanionCharacter.h"
#include "Perception/AIPerceptionStimuliSourceComponent.h"
#include "Perception/AISense_Sight.h"
// Sets default values
ACompanionCharacter::ACompanionCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ACompanionCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ACompanionCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ACompanionCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
UBehaviorTree* ACompanionCharacter::GetBehaviorTree() const
{
return BehaviorTree;
}
void ACompanionCharacter::SetupStimuliSourceComponent()
{
StimuliSourceComponent = CreateDefaultSubobject<UAIPerceptionStimuliSourceComponent>(TEXT("Stimuli Source Component"));
if (IsValid(StimuliSourceComponent))
{
StimuliSourceComponent->RegisterForSense(TSubclassOf<UAISense_Sight>());
StimuliSourceComponent->RegisterWithPerceptionSystem();
}
}

View File

@ -0,0 +1,38 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/BehaviorTree.h"
#include "GameFramework/Character.h"
#include "CompanionCharacter.generated.h"
UCLASS()
class ENDLESSVENDETTA_API ACompanionCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
ACompanionCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
UBehaviorTree* BehaviorTree;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION(BlueprintCallable, Category = "AI")
UBehaviorTree* GetBehaviorTree() const;
private:
class UAIPerceptionStimuliSourceComponent* StimuliSourceComponent;
void SetupStimuliSourceComponent();
};