Add PerceptionComponent to `PlayerCharacter` and `EnemyCharacter`
This commit is contained in:
parent
8a7ee5faee
commit
6127b5cd81
|
@ -8,6 +8,15 @@ AEnemyAIController::AEnemyAIController(const FObjectInitializer& object_initiali
|
|||
{
|
||||
Blackboard = CreateDefaultSubobject<UBlackboardComponent>(TEXT("Blackboard"));
|
||||
BehaviorTree = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("Behavior Tree"));
|
||||
PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component"));
|
||||
AIPerception = PerceptionComponent;
|
||||
|
||||
UAISenseConfig_Sight* ConfigSight = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Sense Config"));
|
||||
ConfigSight->SightRadius = 1000.0f;
|
||||
ConfigSight->LoseSightRadius = 1000.0f;
|
||||
ConfigSight->PeripheralVisionAngleDegrees = 30.0f;
|
||||
|
||||
AIPerception->ConfigureSense(*ConfigSight);
|
||||
}
|
||||
|
||||
void AEnemyAIController::OnPossess(APawn* InPawn)
|
||||
|
@ -98,7 +107,7 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray<AActor*>& actors)
|
|||
}
|
||||
|
||||
FActorPerceptionBlueprintInfo perceptionInfo;
|
||||
GetPerceptionComponent()->GetActorsPerception(actor, perceptionInfo);
|
||||
PerceptionComponent->GetActorsPerception(actor, perceptionInfo);
|
||||
|
||||
for (auto& stimulus : perceptionInfo.LastSensedStimuli)
|
||||
{
|
||||
|
@ -107,6 +116,8 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray<AActor*>& actors)
|
|||
continue;
|
||||
}
|
||||
|
||||
Blackboard->SetValueAsObject("TargetActor", actor);
|
||||
|
||||
if (stimulus.IsActive())
|
||||
{
|
||||
PlayerCharacter = Cast<APlayerCharacter>(actor);
|
||||
|
|
|
@ -28,6 +28,9 @@ private:
|
|||
|
||||
APlayerCharacter* PlayerCharacter;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||
UAIPerceptionComponent* AIPerception;
|
||||
|
||||
public:
|
||||
AEnemyAIController(const FObjectInitializer& object_initializer);
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ class NAKATOMI_API AEnemyCharacter : public ANakatomiCharacter
|
|||
GENERATED_BODY()
|
||||
|
||||
private:
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||
UAIPerceptionComponent* PerceptionComponent;
|
||||
|
||||
UAISenseConfig_Sight* SightConfig;
|
||||
|
|
|
@ -81,6 +81,7 @@ private:
|
|||
|
||||
class UUserWidget* currentPlayerHUD;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||
UAIPerceptionStimuliSourceComponent* PerceptionSource;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue