RealDocs

AAIController::UpdateControlRotation

function AIModule Since 4.0
#include "AIController.h"
Access: public Specifiers: virtual

Description

Updates the controller's control rotation each tick to face the current focal point. Called automatically from Tick — override to implement custom rotation behaviour such as smooth turning or ignoring pitch.

Caveats & Gotchas

  • The rotation snaps instantly to the focal point by default — there is no built-in interpolation. Implement your own lerp or use a rotation rate in your override if smooth turning is needed.
  • bSetControlRotationFromPawnOrientation (a UPROPERTY on AAIController) controls fallback behavior when no focus is set. When true, the pawn's own forward direction is used. Understand this flag before overriding UpdateControlRotation.
  • Called from Tick, so any expensive work inside the override adds to per-frame cost for every AI in the scene.

Signature

virtual void UpdateControlRotation(float DeltaTime, bool bUpdatePawn = true)

Parameters

Name Type Description Default
DeltaTime float Time in seconds since the last tick.
bUpdatePawn bool When true, applies the computed control rotation to the possessed pawn immediately. true

Return Type

void

Example

Override to smoothly interpolate rotation toward the focal point C++
void AMyAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn)
{
	APawn* const Pawn = GetPawn();
	if (!Pawn) { return; }

	FVector FocalPt = GetFocalPoint();
	if (FAISystem::IsValidLocation(FocalPt))
	{
		FRotator DesiredRot = (FocalPt - Pawn->GetActorLocation()).Rotation();
		FRotator CurrentRot = GetControlRotation();
		FRotator NewRot = FMath::RInterpTo(CurrentRot, DesiredRot, DeltaTime, 5.f);
		SetControlRotation(NewRot);
		if (bUpdatePawn)
		{
			Pawn->FaceRotation(NewRot, DeltaTime);
		}
	}
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.