Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sets default values
- ACPP_Agent::ACPP_Agent()
- {
- // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
- PrimaryActorTick.bCanEverTick = true;
- m_AIPerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("New AI Controller"));
- m_UAISightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));
- //m_SightSense = CreateDefaultSubobject<UAISense>(TEXT("Sight Sense"));
- }
- void ACPP_Agent::BeginPlay()
- {
- Super::BeginPlay();
- m_pIdleState = new GOAP_Idle(this);
- m_pCurrentBehaviour = m_pIdleState;
- AAIController* pAIController = Cast<AAIController>(GetController());
- if (pAIController)//Null check
- {
- pAIController->SetPerceptionComponent(*m_AIPerceptionComponent);
- m_UAISightConfig->SightRadius = 600.0f;
- m_UAISightConfig->LoseSightRadius = (620.0f);
- m_UAISightConfig->PeripheralVisionAngleDegrees = 90.0f;
- m_UAISightConfig->DetectionByAffiliation.bDetectEnemies = true;
- m_UAISightConfig->DetectionByAffiliation.bDetectNeutrals = true;
- m_UAISightConfig->DetectionByAffiliation.bDetectFriendlies = true;
- m_AIPerceptionComponent->ConfigureSense(*m_UAISightConfig);
- m_AIPerceptionComponent->ConfigureSense(*m_UAISightConfig);
- m_AIPerceptionComponent->SetDominantSense(m_UAISightConfig->GetSenseImplementation());
- UAIPerceptionSystem::RegisterPerceptionStimuliSource(this, UAISense_Sight::StaticClass(), this);
- m_AIPerceptionComponent->OnTargetPerceptionUpdated.AddDynamic(this, &ACPP_Agent::HasSensedObject);
- UE_LOG(LogTemp, Warning, TEXT("Created Function Delegate!"));
- }
- }
- void ACPP_Agent::HasSensedObject(AActor* UpdatedActor, FAIStimulus Stimulus)
- {
- UE_LOG(LogTemp, Warning, TEXT("Successfully sensed!"));
- DrawDebugLine(GetWorld(), GetActorLocation(), UpdatedActor->GetActorLocation(), FColorList::Red, false, 0.1f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement