Advertisement
orfeasel

AI Character Source File

Jan 14th, 2016
16,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include "MyAIController.h"
  2. #include "BehaviorTree/BehaviorTree.h"
  3. #include "Perception/PawnSensingComponent.h"
  4.  
  5. // Sets default values
  6. AAICharacter::AAICharacter()
  7. {
  8.     // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  9.     PrimaryActorTick.bCanEverTick = true;
  10.  
  11.     //Initializing the pawn sensing component
  12.     PawnSensingComp = CreateDefaultSubobject<UPawnSensingComponent>(TEXT("PawnSensingComp"));
  13.     //Set the peripheral vision angle to 90 degrees
  14.     PawnSensingComp->SetPeripheralVisionAngle(90.f);
  15. }
  16.  
  17. // Called when the game starts or when spawned
  18. void AAICharacter::BeginPlay()
  19. {
  20.     Super::BeginPlay();
  21.  
  22.     //Register the function that is going to fire when the character sees a Pawn
  23.     if (PawnSensingComp)
  24.     {
  25.         PawnSensingComp->OnSeePawn.AddDynamic(this, &AAICharacter::OnSeePlayer);
  26.     }
  27. }
  28.  
  29. void AAICharacter::OnSeePlayer(APawn* Pawn)
  30. {
  31.     AMyAIController* AIController = Cast<AMyAIController>(GetController());
  32.     //Set the seen target on the blackboard
  33.     if (AIController)
  34.     {
  35.         GLog->Log("Oh hello there");
  36.         AIController->SetSeenTarget(Pawn);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement