Move Perception Component from EnemyCharacter to EnemyAIController
This commit is contained in:
parent
0dc524e02d
commit
e0d5526a63
|
@ -1,10 +1,14 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "EnemyAIController.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "NakatomiGameInstance.h"
|
||||
#include <Kismet/GameplayStatics.h>
|
||||
#include "NakatomiGameInstance.h"
|
||||
#include "BehaviorTree/BehaviorTree.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "Perception/AIPerceptionComponent.h"
|
||||
|
||||
AEnemyAIController::AEnemyAIController(const FObjectInitializer& object_initializer)
|
||||
{
|
||||
|
@ -13,12 +17,16 @@ AEnemyAIController::AEnemyAIController(const FObjectInitializer& object_initiali
|
|||
PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component"));
|
||||
AIPerception = PerceptionComponent;
|
||||
|
||||
UAISenseConfig_Sight* ConfigSight = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Sense Config"));
|
||||
ConfigSight->SightRadius = 1000.0f;
|
||||
ConfigSight->LoseSightRadius = 1000.0f;
|
||||
ConfigSight->PeripheralVisionAngleDegrees = 30.0f;
|
||||
SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Sense Config"));
|
||||
SightConfig->SightRadius = 700.0f;
|
||||
SightConfig->LoseSightRadius = 850.0f;
|
||||
SightConfig->PeripheralVisionAngleDegrees = 90.0f;
|
||||
SightConfig->SetMaxAge(5.0f);
|
||||
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
|
||||
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
|
||||
|
||||
AIPerception->ConfigureSense(*ConfigSight);
|
||||
AIPerception->SetDominantSense(SightConfig->GetSenseImplementation());
|
||||
AIPerception->ConfigureSense(*SightConfig);
|
||||
}
|
||||
|
||||
void AEnemyAIController::OnPossess(APawn* InPawn)
|
||||
|
@ -28,8 +36,8 @@ void AEnemyAIController::OnPossess(APawn* InPawn)
|
|||
auto enemy = Cast<AEnemyCharacter>(InPawn);
|
||||
check(enemy);
|
||||
|
||||
SetPerceptionComponent(*enemy->GetPerceptionComponent());
|
||||
enemy->GetPerceptionComponent()->OnPerceptionUpdated.AddDynamic(this, &AEnemyAIController::OnPerceptionUpdated);
|
||||
SetPerceptionComponent(*PerceptionComponent);
|
||||
PerceptionComponent->OnPerceptionUpdated.AddDynamic(this, &AEnemyAIController::OnPerceptionUpdated);
|
||||
enemy->GetCharacterMovement()->MaxWalkSpeed = 500.f;
|
||||
enemy->GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
|
||||
enemy->GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath");
|
||||
|
@ -149,7 +157,7 @@ bool AEnemyAIController::TryObtainAttackToken()
|
|||
{
|
||||
HasAttackToken = gameInstance->GetAIAttackTokenManager()->RequestToken();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,9 @@
|
|||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AIController.h"
|
||||
#include "BehaviorTree/BehaviorTreeComponent.h"
|
||||
#include "BehaviorTree/BehaviorTree.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "EnemyCharacter.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "PlayerCharacter.h"
|
||||
#include "Perception/AISenseConfig_Sight.h"
|
||||
#include "EnemyAIController.generated.h"
|
||||
|
||||
/**
|
||||
|
@ -30,6 +27,8 @@ private:
|
|||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||
UAIPerceptionComponent* AIPerception;
|
||||
|
||||
UAISenseConfig_Sight* SightConfig;
|
||||
|
||||
bool HasAttackToken = false;
|
||||
|
||||
public:
|
||||
|
|
|
@ -1,26 +1,12 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "EnemyCharacter.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "EnemyAIController.h"
|
||||
|
||||
#define COLLISION_WEAPON ECC_GameTraceChannel1
|
||||
|
||||
AEnemyCharacter::AEnemyCharacter()
|
||||
{
|
||||
PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component"));
|
||||
|
||||
SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(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);
|
||||
|
||||
RandomWeaponParameters = CreateDefaultSubobject<URandomWeaponParameters>(TEXT("Random Weapon Parameters"));
|
||||
|
||||
GetHealthComponent()->SetMaxHealth(100.0f);
|
||||
|
@ -33,11 +19,6 @@ UBehaviorTree* AEnemyCharacter::GetBehaviourTree()
|
|||
return BehaviourTree;
|
||||
}
|
||||
|
||||
UAIPerceptionComponent* AEnemyCharacter::GetPerceptionComponent()
|
||||
{
|
||||
return PerceptionComponent;
|
||||
}
|
||||
|
||||
void AEnemyCharacter::OnFire()
|
||||
{
|
||||
CurrentWeapon->SetCurrentWeaponStatus(Firing);
|
||||
|
@ -53,7 +34,7 @@ void AEnemyCharacter::OnFire()
|
|||
CurrentWeapon->SetCurrentWeaponStatus(Cooldown);
|
||||
|
||||
GetWorldTimerManager().SetTimer(CooldownTimerHandle, this, &AEnemyCharacter::WeaponCooldownHandler,
|
||||
CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true);
|
||||
CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true);
|
||||
}
|
||||
|
||||
void AEnemyCharacter::WeaponCooldownHandler()
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#include "CoreMinimal.h"
|
||||
#include "NakatomiCharacter.h"
|
||||
#include "BehaviorTree/BehaviorTreeComponent.h"
|
||||
#include "Perception/AIPerceptionComponent.h"
|
||||
#include <Perception/AISenseConfig_Sight.h>
|
||||
#include "RandomWeaponParameters.h"
|
||||
#include "EnemyCharacter.generated.h"
|
||||
|
||||
|
@ -20,11 +18,6 @@ class NAKATOMI_API AEnemyCharacter : public ANakatomiCharacter
|
|||
GENERATED_BODY()
|
||||
|
||||
private:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||
UAIPerceptionComponent* PerceptionComponent;
|
||||
|
||||
UAISenseConfig_Sight* SightConfig;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
|
||||
UBehaviorTree* BehaviourTree;
|
||||
|
||||
|
@ -38,8 +31,6 @@ public:
|
|||
|
||||
UBehaviorTree* GetBehaviourTree();
|
||||
|
||||
UAIPerceptionComponent* GetPerceptionComponent();
|
||||
|
||||
virtual void OnFire() override;
|
||||
|
||||
void WeaponCooldownHandler();
|
||||
|
|
Loading…
Reference in New Issue