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::UpdateControlRotation(float DeltaTime, bool bUpdatePawn) { // Look toward focus FVector FocalPoint = GetFocalPoint(); if( !FocalPoint.IsZero() && GetPawn()) { FVector Direction = FocalPoint - GetPawn()->GetActorLocation(); FRotator NewControlRotation = Direction.Rotation(); // Don't pitch view of walking pawns unless looking at another pawn if ( GetPawn()->GetMovementComponent() && GetPawn()->GetMovementComponent()->IsMovingOnGround() && PathFollowingComponent && (!PathFollowingComponent->GetMoveGoal() || !Cast<APawn>(PathFollowingComponent->GetMoveGoal()) ) ) { NewControlRotation.Pitch = 0.f; } NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw); SetControlRotation(NewControlRotation); APawn* const P = GetPawn(); if (P && bUpdatePawn) { P->FaceRotation(NewControlRotation, DeltaTime); } } }
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); } } } }