Add reworked Worker Enemy AI #3
							
								
								
									
										
											BIN
										
									
								
								Content/Enemy/BT_Attacking_State.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											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)
									
									
									
									
								
							
							
						
						
									
										
											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)
									
									
									
									
								
							
							
						
						
									
										
											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
									
								
							
							
						
						
									
										
											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)
									
									
									
									
								
							
							
						
						
									
										
											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)
									
									
									
									
								
							
							
						
						
									
										
											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)
									
									
									
									
								
							
							
						
						
									
										
											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)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Enemy/Worker/C_Worker.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Enemy/Worker/PatrolMovementSpeed.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Enemy/Worker/PatrolMovementSpeed.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										27
									
								
								Source/Nakatomi/Decorators/BTDCanSeeTarget.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Source/Nakatomi/Decorators/BTDCanSeeTarget.cpp
									
									
									
									
									
										Normal 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;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								Source/Nakatomi/Decorators/BTDCanSeeTarget.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Source/Nakatomi/Decorators/BTDCanSeeTarget.h
									
									
									
									
									
										Normal 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;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										14
									
								
								Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.cpp
									
									
									
									
									
										Normal 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;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								Source/Nakatomi/Decorators/BTDIsHealthBelowThreshold.h
									
									
									
									
									
										Normal 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;
 | 
			
		||||
};
 | 
			
		||||
@ -4,6 +4,9 @@
 | 
			
		||||
#include "EnemyAIController.h"
 | 
			
		||||
#include "EnemyHealthComponent.h"
 | 
			
		||||
#include "InteractableComponent.h"
 | 
			
		||||
#include "BehaviorTree/BehaviorTree.h"
 | 
			
		||||
#include "BehaviorTree/BlackboardComponent.h"
 | 
			
		||||
#include "BehaviorTree/BlackboardData.h"
 | 
			
		||||
 | 
			
		||||
#define COLLISION_WEAPON	ECC_GameTraceChannel1
 | 
			
		||||
 | 
			
		||||
@ -16,7 +19,7 @@ AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) :
 | 
			
		||||
	GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
 | 
			
		||||
	GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath");
 | 
			
		||||
	GetHealthComponent()->SetMaxHealth(100.0f);
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	this->Tags.Add(FName("Enemy"));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -54,6 +57,10 @@ void AEnemyCharacter::WeaponCooldownHandler()
 | 
			
		||||
void AEnemyCharacter::BeginPlay()
 | 
			
		||||
{
 | 
			
		||||
	Super::BeginPlay();
 | 
			
		||||
 | 
			
		||||
	AEnemyAIController* controller = Cast<AEnemyAIController>(GetController());
 | 
			
		||||
	controller->GetBlackboardComponent()->SetValueAsFloat("CurrentHealth", GetHealthComponent()->GetCurrentHealth());
 | 
			
		||||
	GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -55,4 +55,7 @@ private:
 | 
			
		||||
	virtual void CalculateHits(TArray<FHitResult>* hits) override;
 | 
			
		||||
 | 
			
		||||
	virtual void ProcessHits(TArray<FHitResult> hits) override;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	virtual void OnDamaged() override;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user