/
Azarel
/
Metro2
Обзор
Документация
Войти
/
Azarel
/
Metro2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/GameJam/Private/Base_AIController.cpp
59 строк
2 KB
Arsenii
Initial commit
12 дек 2023, 21:31
12 дек 2023, 21:31
3c2092c
Код
Авторство
О чём код?
// Fill out your copyright notice in the Description page of Project Settings. #include "Base_AIController.h" #include "EnemyBase.h" #include "Perception/AIPerceptionComponent.h" #include "Perception/AISenseConfig_Sight.h" #include "BehaviorTree/BlackboardComponent.h" #include "BasePlayer.h" ABase_AIController::ABase_AIController(FObjectInitializer const& ObjectInitializer) { SetupPerceptionSystem(); } void ABase_AIController::OnPossess(APawn* InPawn) { Super::OnPossess(InPawn); if (AEnemyBase* const enemyBase = Cast<AEnemyBase>(InPawn)) { if (UBehaviorTree* const tree = enemyBase->GetBehaviorTree()) { UBlackboardComponent* b; UseBlackboard(tree->BlackboardAsset, b); Blackboard = b; RunBehaviorTree(tree); } } } void ABase_AIController::SetupPerceptionSystem() { SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config")); if (SightConfig) { SetPerceptionComponent(*CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component"))); SightConfig->SightRadius = 500.f; SightConfig->LoseSightRadius = SightConfig->SightRadius + 25.f; SightConfig->PeripheralVisionAngleDegrees = 90.f; SightConfig->SetMaxAge(5.f); SightConfig->AutoSuccessRangeFromLastSeenLocation = 520.f; SightConfig->DetectionByAffiliation.bDetectEnemies = true; SightConfig->DetectionByAffiliation.bDetectFriendlies = true; SightConfig->DetectionByAffiliation.bDetectNeutrals = true; GetPerceptionComponent()->SetDominantSense(*SightConfig->GetSenseImplementation()); GetPerceptionComponent()->OnTargetPerceptionUpdated.AddDynamic(this, &ABase_AIController::OnTargetDetected); GetPerceptionComponent()->ConfigureSense(*SightConfig); } } void ABase_AIController::OnTargetDetected(AActor* Actor, FAIStimulus const Stimulus) { if (auto* const ch = Cast<ABasePlayer>(Actor)) { GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", Stimulus.WasSuccessfullySensed()); } }