AMurphysLawAIController::AMurphysLawAIController() // Enable navigation within crowds //: Super(FObjectInitializer::Get().SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent"))) { bWantsPlayerState = true; // bAllowStrafe = true; // ?? Run and shoot // The action logic of the AI (assigned from blueprint) BehaviorTreeAsset = nullptr; // No pawn is yet controlled bPossessPawn = false; // Create and configure sight sense UAISenseConfig_Sight* SightSenseConfig = CreateDefaultSubobject<UAISenseConfig_Sight>("Sight sense"); SightSenseConfig->PeripheralVisionAngleDegrees = 90.f; SightSenseConfig->DetectionByAffiliation.bDetectEnemies = true; SightSenseConfig->DetectionByAffiliation.bDetectNeutrals = true; SightSenseConfig->DetectionByAffiliation.bDetectFriendlies = true; SightSenseConfig->SightRadius = 100.f * 20.f; SightSenseConfig->LoseSightRadius = SightSenseConfig->SightRadius * 1.2f; SightSenseConfig->AutoSuccessRangeFromLastSeenLocation = SightSenseConfig->SightRadius * 1.1f; UAISenseConfig_Hearing* HearingSenseConfig = CreateDefaultSubobject<UAISenseConfig_Hearing>("Hearing sense"); HearingSenseConfig->HearingRange = 100.f * 50.f; HearingSenseConfig->LoSHearingRange = 100.f * 150.f; HearingSenseConfig->bUseLoSHearing = true; HearingSenseConfig->DetectionByAffiliation.bDetectEnemies = true; HearingSenseConfig->DetectionByAffiliation.bDetectNeutrals = true; HearingSenseConfig->DetectionByAffiliation.bDetectFriendlies = true; // Create perceptions system UAIPerceptionComponent* Perceptions = CreateDefaultSubobject<UAIPerceptionComponent>("PerceptionComp"); Perceptions->ConfigureSense(*SightSenseConfig); Perceptions->ConfigureSense(*HearingSenseConfig); Perceptions->SetDominantSense(SightSenseConfig->GetSenseImplementation()); Perceptions->Deactivate(); SetPerceptionComponent(*Perceptions); }
AWalkerAIController::AWalkerAIController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent"))) { PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.TickInterval = UPDATE_TIME_IN_SECONDS; auto Perception = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("AIPerception Component")); check(Perception != nullptr); SetPerceptionComponent(*Perception); SightConfiguration = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("SightConfiguration")); SightConfiguration->SightRadius = WALKER_SIGHT_RADIUS; SightConfiguration->LoseSightRadius = (WALKER_SIGHT_RADIUS + 100.0f); SightConfiguration->PeripheralVisionAngleDegrees = WALKER_PERIPHERAL_VISION_ANGLE_IN_DEGREES; SightConfiguration->DetectionByAffiliation.bDetectEnemies = true; SightConfiguration->DetectionByAffiliation.bDetectNeutrals = true; SightConfiguration->DetectionByAffiliation.bDetectFriendlies = true; Perception->ConfigureSense(*SightConfiguration); Perception->SetDominantSense(SightConfiguration->GetSenseImplementation()); Perception->OnPerceptionUpdated.AddDynamic(this, &AWalkerAIController::SenseActors); }