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"));
|
Blackboard = CreateDefaultSubobject<UBlackboardComponent>(TEXT("Blackboard"));
|
||||||
BehaviorTree = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("Behavior Tree"));
|
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)
|
void AEnemyAIController::OnPossess(APawn* InPawn)
|
||||||
|
@ -98,7 +107,7 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray<AActor*>& actors)
|
||||||
}
|
}
|
||||||
|
|
||||||
FActorPerceptionBlueprintInfo perceptionInfo;
|
FActorPerceptionBlueprintInfo perceptionInfo;
|
||||||
GetPerceptionComponent()->GetActorsPerception(actor, perceptionInfo);
|
PerceptionComponent->GetActorsPerception(actor, perceptionInfo);
|
||||||
|
|
||||||
for (auto& stimulus : perceptionInfo.LastSensedStimuli)
|
for (auto& stimulus : perceptionInfo.LastSensedStimuli)
|
||||||
{
|
{
|
||||||
|
@ -107,6 +116,8 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray<AActor*>& actors)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Blackboard->SetValueAsObject("TargetActor", actor);
|
||||||
|
|
||||||
if (stimulus.IsActive())
|
if (stimulus.IsActive())
|
||||||
{
|
{
|
||||||
PlayerCharacter = Cast<APlayerCharacter>(actor);
|
PlayerCharacter = Cast<APlayerCharacter>(actor);
|
||||||
|
|
|
@ -28,6 +28,9 @@ private:
|
||||||
|
|
||||||
APlayerCharacter* PlayerCharacter;
|
APlayerCharacter* PlayerCharacter;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||||
|
UAIPerceptionComponent* AIPerception;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AEnemyAIController(const FObjectInitializer& object_initializer);
|
AEnemyAIController(const FObjectInitializer& object_initializer);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ class NAKATOMI_API AEnemyCharacter : public ANakatomiCharacter
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||||
UAIPerceptionComponent* PerceptionComponent;
|
UAIPerceptionComponent* PerceptionComponent;
|
||||||
|
|
||||||
UAISenseConfig_Sight* SightConfig;
|
UAISenseConfig_Sight* SightConfig;
|
||||||
|
|
|
@ -81,6 +81,7 @@ private:
|
||||||
|
|
||||||
class UUserWidget* currentPlayerHUD;
|
class UUserWidget* currentPlayerHUD;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
|
||||||
UAIPerceptionStimuliSourceComponent* PerceptionSource;
|
UAIPerceptionStimuliSourceComponent* PerceptionSource;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue