From 33e0d24d34e1d4482e13d439ba3402959902a30a Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Fri, 3 Feb 2023 01:29:14 +0000 Subject: [PATCH] Add EnemyCharacter class --- Source/Nakatomi/EnemyCharacter.cpp | 40 ++++++++++++++++++++++++++++++ Source/Nakatomi/EnemyCharacter.h | 38 ++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Source/Nakatomi/EnemyCharacter.cpp create mode 100644 Source/Nakatomi/EnemyCharacter.h diff --git a/Source/Nakatomi/EnemyCharacter.cpp b/Source/Nakatomi/EnemyCharacter.cpp new file mode 100644 index 0000000..75cd6cb --- /dev/null +++ b/Source/Nakatomi/EnemyCharacter.cpp @@ -0,0 +1,40 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "EnemyCharacter.h" +#include "GameFramework/CharacterMovementComponent.h" +#include "EnemyAIController.h" + +AEnemyCharacter::AEnemyCharacter() +{ + PerceptionComponent = CreateDefaultSubobject(TEXT("Perception Component")); + + SightConfig = CreateDefaultSubobject(TEXT("Sight Configuration")); + SightConfig->SightRadius = 700.0f; + SightConfig->LoseSightRadius = 850.0f; + SightConfig->PeripheralVisionAngleDegrees = 90.0f; + SightConfig->SetMaxAge(5.0f); + SightConfig->DetectionByAffiliation.bDetectEnemies = true; + SightConfig->DetectionByAffiliation.bDetectNeutrals = true; + + PerceptionComponent->SetDominantSense(SightConfig->GetSenseImplementation()); + PerceptionComponent->ConfigureSense(*SightConfig); + + GetHealthComponent()->SetMaxHealth(100.0f); + + this->Tags.Add(FName("Enemy")); +} + +UBehaviorTree* AEnemyCharacter::GetBehaviourTree() +{ + return BehaviourTree; +} + +UAIPerceptionComponent* AEnemyCharacter::GetPerceptionComponent() +{ + return PerceptionComponent; +} + +void AEnemyCharacter::BeginPlay() +{ + Super::BeginPlay(); +} diff --git a/Source/Nakatomi/EnemyCharacter.h b/Source/Nakatomi/EnemyCharacter.h new file mode 100644 index 0000000..911a2d8 --- /dev/null +++ b/Source/Nakatomi/EnemyCharacter.h @@ -0,0 +1,38 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "NakatomiCharacter.h" +#include "BehaviorTree/BehaviorTreeComponent.h" +#include "Perception/AIPerceptionComponent.h" +#include +#include "EnemyCharacter.generated.h" + + +/** + * + */ +UCLASS() +class NAKATOMI_API AEnemyCharacter : public ANakatomiCharacter +{ + GENERATED_BODY() + +private: + UAIPerceptionComponent* PerceptionComponent; + + UAISenseConfig_Sight* SightConfig; + + UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) + UBehaviorTree* BehaviourTree; + +public: + AEnemyCharacter(); + + UBehaviorTree* GetBehaviourTree(); + + UAIPerceptionComponent* GetPerceptionComponent(); + +protected: + virtual void BeginPlay() override; +};