UpdateControlRotation Pitch bug.. Bonus fix included

In the AIController theres this bit in the UpdateControlRotation

// Don't pitch view unless looking at another pawn
		if (NewControlRotation.Pitch != 0 && Cast<APawn>(GetFocusActor()) == nullptr)
		{
			NewControlRotation.Pitch = 0.f;
		}

This is wrong. What is intended is the character not to pitch while they are moving while not focused on an actor. What this does is override pitch regardless of you focus priorities. Here’s how you fix this:

EAIFocusPriority::Type AAIController::GetFocalPointAndPriority(FVector& OutVector) const
 {
	  OutVector = FAISystem::InvalidLocation;
	  EAIFocusPriority::Type Result; 

	 // find focus with highest priority
	 for (int32 Index = FocusInformation.Priorities.Num() - 1; Index >= 0; --Index)
	 {
		 const FFocusKnowledge::FFocusItem& FocusItem = FocusInformation.Priorities[Index];
		 AActor* FocusActor = FocusItem.Actor.Get();
		 if (FocusActor)
		 {
			 OutVector = GetFocalPointOnActor(FocusActor);
			 Result = Index; 
			 break;
		 }
		 else if (FAISystem::IsValidLocation(FocusItem.Position))
		 {
			 OutVector = FocusItem.Position;
			 Result = Index;
			 break;
		 }
	 }

	 return Result;
 }

This function returns the focal point along with the priority with this you can update UpdateControlRotation like so

void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn)
 {
	 APawn* const MyPawn = GetPawn();
	 if (MyPawn)
	 {

		 //FocusInformation.Priorities

		 const FRotator InitialControlRotation = GetControlRotation();
		 FRotator NewControlRotation = InitialControlRotation;

		 // Look toward focus
		 FVector FocalPoint; 
		 EAIFocusPriority::Type PointPriority = GetFocalPointAndPriority(FocalPoint); // Thanks Frank!

		 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 (PointPriority == EAIFocusPriority::Move  &&  Cast<APawn>(GetFocusActor()) == nullptr)
		 {
			 NewControlRotation.Pitch = 0.f;
		 }
		 
		 if (InitialControlRotation.Equals(NewControlRotation, 1e-3f) == false)
		 {
			 SetControlRotation(NewControlRotation);

			 if (bUpdatePawn)
			 {
				 MyPawn->FaceRotation(NewControlRotation, DeltaTime);
			 }
		 }
	 }
 }

And now it works as intended!

1 Like

Hey xAnnihilationx,

Thank you for the suggestion as to how you think the AIController pitch setting should work while the possessed Pawn is/isn’t moving, however at this time we believe that the issue you are describing is not actually a bug with the Unreal Engine, and so we are not able to take any further action on this.

Furthermore, if you would like to submit a pull request so the developers can see about integrating your functionality over the current, you can being to learn how to get the source code (if do not already have it), here:

[][1]

[1]: