15{
16 AAIController* AIController = OwnerComp.GetAIOwner();
17 UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
18
19 if (AIController && BlackboardComp)
20 {
21 APawn* AIPawn = AIController->GetPawn();
22 AActor* TargetActor = Cast<AActor>(BlackboardComp->GetValueAsObject(BlackboardKey.SelectedKeyName));
23 if (AIPawn && TargetActor)
24 {
25 FVector LookAtDirection = TargetActor->GetActorLocation() - AIPawn->GetActorLocation();
26 LookAtDirection.Z = 0.0f;
27
28 FRotator TargetRotation = LookAtDirection.Rotation();
29 AIPawn->SetActorRotation(TargetRotation);
30
31 return EBTNodeResult::Succeeded;
32 }
33 }
34 return EBTNodeResult::Failed;
35}