void AAIController::GrabDebugSnapshot(FVisualLogEntry* Snapshot) const { FVisualLogStatusCategory MyCategory; MyCategory.Category = TEXT("AI Controller"); MyCategory.Add(TEXT("Pawn"), GetNameSafe(GetPawn())); AActor* FocusActor = GetFocusActor(); MyCategory.Add(TEXT("Focus"), GetDebugName(FocusActor)); if (FocusActor == nullptr) { MyCategory.Add(TEXT("Focus Location"), TEXT_AI_LOCATION(GetFocalPoint())); } Snapshot->Status.Add(MyCategory); if (GetPawn()) { Snapshot->Location = GetPawn()->GetActorLocation(); } if (PathFollowingComponent) { PathFollowingComponent->DescribeSelfToVisLog(Snapshot); } if (BrainComponent != NULL) { BrainComponent->DescribeSelfToVisLog(Snapshot); } if (PerceptionComponent != NULL) { PerceptionComponent->DescribeSelfToVisLog(Snapshot); } }
void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn) { // Look toward focus FVector FocalPoint = GetFocalPoint(); APawn* const Pawn = GetPawn(); if (Pawn) { FVector Direction = FAISystem::IsValidLocation(FocalPoint) ? (FocalPoint - Pawn->GetPawnViewLocation()) : Pawn->GetActorForwardVector(); FRotator NewControlRotation = Direction.Rotation(); // Don't pitch view unless looking at another pawn if (Cast<APawn>(GetFocusActor()) == nullptr) { NewControlRotation.Pitch = 0.f; } NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw); if (GetControlRotation().Equals(NewControlRotation, 1e-3f) == false) { SetControlRotation(NewControlRotation); if (bUpdatePawn) { Pawn->FaceRotation(NewControlRotation, DeltaTime); } } } }
void AAIController::DisplayDebug(class UCanvas* Canvas, const TArray<FName>& DebugDisplay, float& YL, float& YPos) { Super::DisplayDebug(Canvas, DebugDisplay, YL, YPos); static FName NAME_AI = FName(TEXT("AI")); if (DebugDisplay.Contains(NAME_AI)) { if (PathFollowingComponent) { PathFollowingComponent->DisplayDebug(Canvas, DebugDisplay, YL, YPos); } if ( GetFocusActor() ) { Canvas->DrawText(GEngine->GetSmallFont(), FString::Printf(TEXT(" Focus %s"), *GetFocusActor()->GetName()), 4.0f, YPos); YPos += YL; } } }
void AAIController::DisplayDebug(UCanvas* Canvas, const FDebugDisplayInfo& DebugDisplay, float& YL, float& YPos) { Super::DisplayDebug(Canvas, DebugDisplay, YL, YPos); static FName NAME_AI = FName(TEXT("AI")); if (DebugDisplay.IsDisplayOn(NAME_AI)) { if (PathFollowingComponent) { PathFollowingComponent->DisplayDebug(Canvas, DebugDisplay, YL, YPos); } AActor* FocusActor = GetFocusActor(); if (FocusActor) { YL = Canvas->DrawText(GEngine->GetSmallFont(), FString::Printf(TEXT(" Focus %s"), *FocusActor->GetName()), 4.0f, YPos); YPos += YL; } } }
void AAIController::DisplayDebug(UCanvas* Canvas, const FDebugDisplayInfo& DebugDisplay, float& YL, float& YPos) { Super::DisplayDebug(Canvas, DebugDisplay, YL, YPos); static FName NAME_AI = FName(TEXT("AI")); if (DebugDisplay.IsDisplayOn(NAME_AI)) { if (PathFollowingComponent) { PathFollowingComponent->DisplayDebug(Canvas, DebugDisplay, YL, YPos); } AActor* FocusActor = GetFocusActor(); if (FocusActor) { FDisplayDebugManager& DisplayDebugManager = Canvas->DisplayDebugManager; DisplayDebugManager.DrawString(FString::Printf(TEXT(" Focus %s"), *FocusActor->GetName())); } } }
void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn) { APawn* const MyPawn = GetPawn(); if (MyPawn) { FRotator NewControlRotation = GetControlRotation(); // Look toward focus const FVector FocalPoint = GetFocalPoint(); if (FAISystem::IsValidLocation(FocalPoint)) { NewControlRotation = (FocalPoint - MyPawn->GetPawnViewLocation()).Rotation(); } else if (bSetControlRotationFromPawnOrientation) { NewControlRotation = MyPawn->GetActorRotation(); } // Don't pitch view unless looking at another pawn if (NewControlRotation.Pitch != 0 && Cast<APawn>(GetFocusActor()) == nullptr) { NewControlRotation.Pitch = 0.f; } SetControlRotation(NewControlRotation); if (bUpdatePawn) { const FRotator CurrentPawnRotation = MyPawn->GetActorRotation(); if (CurrentPawnRotation.Equals(NewControlRotation, 1e-3f) == false) { MyPawn->FaceRotation(NewControlRotation, DeltaTime); } } } }