Simplify moving to player character
This commit is contained in:
parent
e07abfbcfc
commit
3e14d6f6e3
|
@ -36,11 +36,9 @@ void AVampireAIController::Tick(float DeltaTime)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
if (AVampireCharacter* Player = Cast<AVampireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)))
|
if (PlayerCharacter)
|
||||||
{
|
{
|
||||||
Blackboard->SetValueAsObject("Player", Player);
|
Blackboard->SetValueAsVector("PlayerLocation", PlayerCharacter->GetActorLocation());
|
||||||
auto location = Player->GetActorLocation();
|
|
||||||
Blackboard->SetValueAsVector("PlayerLocation", location);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,11 +52,18 @@ void AVampireAIController::OnPossess(APawn* InPawn)
|
||||||
EnemyCharacter->GetHealthComponent()->OnDamaged.AddDynamic(this, &AVampireAIController::OnDamaged);
|
EnemyCharacter->GetHealthComponent()->OnDamaged.AddDynamic(this, &AVampireAIController::OnDamaged);
|
||||||
EnemyCharacter->GetHealthComponent()->OnDeath.AddDynamic(this, &AVampireAIController::OnDeath);
|
EnemyCharacter->GetHealthComponent()->OnDeath.AddDynamic(this, &AVampireAIController::OnDeath);
|
||||||
|
|
||||||
|
PlayerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
|
||||||
|
|
||||||
if (UBehaviorTree* bt = EnemyCharacter->GetBehaviorTree())
|
if (UBehaviorTree* bt = EnemyCharacter->GetBehaviorTree())
|
||||||
{
|
{
|
||||||
Blackboard->InitializeBlackboard(*bt->BlackboardAsset);
|
Blackboard->InitializeBlackboard(*bt->BlackboardAsset);
|
||||||
BehaviorTree->StartTree(*bt);
|
BehaviorTree->StartTree(*bt);
|
||||||
Blackboard->SetValueAsObject("SelfActor", EnemyCharacter);
|
Blackboard->SetValueAsObject("SelfActor", EnemyCharacter);
|
||||||
|
|
||||||
|
if (PlayerCharacter)
|
||||||
|
{
|
||||||
|
Blackboard->SetValueAsObject("Player", PlayerCharacter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class VAMPIRES_API AVampireAIController : public AAIController
|
||||||
|
|
||||||
UBehaviorTreeComponent* BehaviorTree;
|
UBehaviorTreeComponent* BehaviorTree;
|
||||||
|
|
||||||
APlayerCharacter* PlayerCharacter;
|
ACharacter* PlayerCharacter;
|
||||||
|
|
||||||
AEnemyCharacter* EnemyCharacter;
|
AEnemyCharacter* EnemyCharacter;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue