So how do you rotate it? I tried it as a service, but it didn’t work. Below is the service code.
void UBTService_SeePlayer::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
APawn* Player = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
AAIController* AIController = OwnerComp.GetAIOwner();
APawn* NPC = AIController->GetPawn();
if (AIController->LineOfSightTo(Player))
{
UWorld* World = NPC->GetWorld();
FName PlayerPositionName = TEXT("PlayerPos");
FVector PlayerPosition = Player->GetActorLocation();
OwnerComp.GetBlackboardComponent()->SetValueAsVector(PlayerPositionName, Player->GetActorLocation());
FName TargetName = TEXT("Target");
OwnerComp.GetBlackboardComponent()->SetValueAsObject(TargetName, Player);
DrawDebugPoint(World, Player->GetActorLocation(), 10.0f, FColor::Green, false, 0.2f);
DrawDebugLine(World, NPC->GetActorLocation(), Player->GetActorLocation(), FColor::Green, false, 0.27f);
}
else
{
FName TargetName = TEXT("Target");
OwnerComp.GetBlackboardComponent()->SetValueAsObject(TargetName, nullptr);
}
}