Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Sets default values
  2. ACPP_Agent::ACPP_Agent()
  3. {
  4.     // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  5.     PrimaryActorTick.bCanEverTick = true;
  6.     m_AIPerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("New AI Controller"));
  7.     m_UAISightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));
  8.  
  9.     //m_SightSense = CreateDefaultSubobject<UAISense>(TEXT("Sight Sense"));
  10. }
  11.  
  12. void ACPP_Agent::BeginPlay()
  13. {
  14.     Super::BeginPlay();
  15.  
  16.     m_pIdleState = new GOAP_Idle(this);
  17.     m_pCurrentBehaviour = m_pIdleState;
  18.  
  19.     AAIController* pAIController = Cast<AAIController>(GetController());
  20.  
  21.     if (pAIController)//Null check
  22.     {
  23.         pAIController->SetPerceptionComponent(*m_AIPerceptionComponent);
  24.  
  25.         m_UAISightConfig->SightRadius = 600.0f;
  26.         m_UAISightConfig->LoseSightRadius = (620.0f);
  27.         m_UAISightConfig->PeripheralVisionAngleDegrees = 90.0f;
  28.         m_UAISightConfig->DetectionByAffiliation.bDetectEnemies = true;
  29.         m_UAISightConfig->DetectionByAffiliation.bDetectNeutrals = true;
  30.         m_UAISightConfig->DetectionByAffiliation.bDetectFriendlies = true;
  31.  
  32.         m_AIPerceptionComponent->ConfigureSense(*m_UAISightConfig);
  33.  
  34.         m_AIPerceptionComponent->ConfigureSense(*m_UAISightConfig);
  35.         m_AIPerceptionComponent->SetDominantSense(m_UAISightConfig->GetSenseImplementation());
  36.         UAIPerceptionSystem::RegisterPerceptionStimuliSource(this, UAISense_Sight::StaticClass(), this);
  37.  
  38.         m_AIPerceptionComponent->OnTargetPerceptionUpdated.AddDynamic(this, &ACPP_Agent::HasSensedObject);
  39.  
  40.         UE_LOG(LogTemp, Warning, TEXT("Created Function Delegate!"));
  41.     }
  42. }
  43.  
  44. void ACPP_Agent::HasSensedObject(AActor* UpdatedActor, FAIStimulus Stimulus)
  45. {
  46.     UE_LOG(LogTemp, Warning, TEXT("Successfully sensed!"));
  47.     DrawDebugLine(GetWorld(), GetActorLocation(), UpdatedActor->GetActorLocation(), FColorList::Red, false, 0.1f);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement