Refine Ranged Enemy functionality and hide on low health

This commit is contained in:
baz 2024-02-27 23:18:07 +00:00
parent cc21d38a0f
commit 6a30ddae07
15 changed files with 130 additions and 17 deletions

BIN
Content/Enemy/BT_Attacking_State.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/BT_Find_Cover.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/EQS/AttackTarget.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/EQS/EQS_FindIdealRange.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Enemy/Worker/AIC_Worker.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/Worker/BB_Worker.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/Worker/BT_Worker.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemy/Worker/C_Worker.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "../Decorators/BTDCanSeeTarget.h"
#include "AIController.h"
#include "BehaviorTree/BlackboardComponent.h"
bool UBTDCanSeeTarget::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
FHitResult HitResult;
FVector Start = OwnerComp.GetAIOwner()->GetPawn()->GetActorLocation();
UBlackboardComponent* BlackboardComponent = OwnerComp.GetBlackboardComponent();
AActor* TargetActor = Cast<AActor>(BlackboardComponent->GetValueAsObject(TargetActorKey.SelectedKeyName));
FVector End = TargetActor->GetActorLocation();
GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn);
if (HitResult.GetActor())
{
return true;
}
return false;
}

View File

@ -0,0 +1,24 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/BTDecorator.h"
#include "BTDCanSeeTarget.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API UBTDCanSeeTarget : public UBTDecorator
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key"))
FBlackboardKeySelector TargetActorKey;
protected:
virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override;
};

View File

@ -0,0 +1,14 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "../Decorators/BTDIsHealthBelowThreshold.h"
#include "BehaviorTree/BlackboardComponent.h"
bool UBTDIsHealthBelowThreshold::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
UBlackboardComponent* BlackboardComponent = OwnerComp.GetBlackboardComponent();
float currentHealth = BlackboardComponent->GetValueAsFloat(CurrentHealthKey.SelectedKeyName);
return currentHealth <= HealthThreshold ? true : false;
}

View File

@ -0,0 +1,29 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/BTDecorator.h"
#include "BTDIsHealthBelowThreshold.generated.h"
/**
*
*/
UCLASS()
class NAKATOMI_API UBTDIsHealthBelowThreshold : public UBTDecorator
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Current Health Key"))
FBlackboardKeySelector CurrentHealthKey;
UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Health Threshold"))
float HealthThreshold = 25.0f;
protected:
virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override;
};

View File

@ -4,6 +4,9 @@
#include "EnemyAIController.h" #include "EnemyAIController.h"
#include "EnemyHealthComponent.h" #include "EnemyHealthComponent.h"
#include "InteractableComponent.h" #include "InteractableComponent.h"
#include "BehaviorTree/BehaviorTree.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "BehaviorTree/BlackboardData.h"
#define COLLISION_WEAPON ECC_GameTraceChannel1 #define COLLISION_WEAPON ECC_GameTraceChannel1
@ -54,6 +57,10 @@ void AEnemyCharacter::WeaponCooldownHandler()
void AEnemyCharacter::BeginPlay() void AEnemyCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
AEnemyAIController* controller = Cast<AEnemyAIController>(GetController());
controller->GetBlackboardComponent()->SetValueAsFloat("CurrentHealth", GetHealthComponent()->GetCurrentHealth());
GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
} }
void AEnemyCharacter::PlayOnFireAnimations() void AEnemyCharacter::PlayOnFireAnimations()
@ -130,3 +137,12 @@ void AEnemyCharacter::ProcessHits(TArray<FHitResult> hits)
} }
} }
} }
void AEnemyCharacter::OnDamaged()
{
Super::OnDamaged();
AEnemyAIController* controller = Cast<AEnemyAIController>(GetController());
controller->GetBlackboardComponent()->SetValueAsFloat("CurrentHealth", GetHealthComponent()->GetCurrentHealth());
}

View File

@ -55,4 +55,7 @@ private:
virtual void CalculateHits(TArray<FHitResult>* hits) override; virtual void CalculateHits(TArray<FHitResult>* hits) override;
virtual void ProcessHits(TArray<FHitResult> hits) override; virtual void ProcessHits(TArray<FHitResult> hits) override;
protected:
virtual void OnDamaged() override;
}; };