diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp index eca94318..94ef8372 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/AI_EnemyController.cpp @@ -5,6 +5,7 @@ #include "EnemyCharacter.h" #include "BehaviorTree/BlackboardComponent.h" +#include "EndlessVendetta/EndlessVendettaCharacter.h" #include "Perception/AIPerceptionComponent.h" #include "Perception/AISenseConfig_Sight.h" @@ -43,6 +44,10 @@ void AAI_EnemyController::OnPossess(APawn* InPawn) void AAI_EnemyController::Tick(float DeltaTime) { Super::Tick(DeltaTime); + if (GetBlackboardComponent()->GetValueAsBool("CanSeePlayer")) + { + GetBlackboardComponent()->SetValueAsVector("TargetLocation", GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation()); + } } void AAI_EnemyController::SetupPerceptionSystem() @@ -51,10 +56,10 @@ void AAI_EnemyController::SetupPerceptionSystem() if (IsValid(SightConfig)) { SetPerceptionComponent(*CreateDefaultSubobject(TEXT("Perception Component"))); - SightConfig->SightRadius = 1000.0f; - SightConfig->LoseSightRadius = 1100.0f; - SightConfig->PeripheralVisionAngleDegrees = 90.0f; - SightConfig->SetMaxAge(5.0f); + 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; @@ -67,17 +72,19 @@ void AAI_EnemyController::SetupPerceptionSystem() void AAI_EnemyController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus const Stimulus) { - if (AEnemyCharacter* const EnemyCharacter = Cast(Actor)) + if (AEndlessVendettaCharacter* const PlayerCharacter = Cast(Actor)) { if (Stimulus.WasSuccessfullySensed()) { - GetBlackboardComponent()->SetValueAsObject("TargetActor", Actor); + GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor); GetBlackboardComponent()->SetValueAsVector("TargetLocation", Stimulus.StimulusLocation); + GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", true); } else { GetBlackboardComponent()->ClearValue("TargetActor"); GetBlackboardComponent()->ClearValue("TargetLocation"); + GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", false); } } }