Limiting Pitch Rotation on Object

The AMyFlyingProjectPawn::Tick function updates the actor’s rotation by applying a delta rotation via the AddActorLocalRotation function. Since it only deals with a delta, to limit the pawn’s total pitch you need to get the current rotation and clamp the delta such that the new pitch is within the range you want. The below is one way you could do it.

MyFlyingProjectPawn.h

(Added within class declaration)

UPROPERTY(Category=Movement, EditAnywhere, BlueprintReadWrite)
float MaxPitch;

UPROPERTY(Category=Movement, EditAnywhere, BlueprintReadWrite)
float MinPitch;

MyFlyingProjectPawn.cpp

(Added within constructor)

MaxPitch = 30.f;
MinPitch = -30.f;

(Replacing related lines in Tick function)

const float OldPitch = GetActorRotation().Pitch;
const float MinDeltaPitch = MinPitch - OldPitch;
const float MaxDeltaPitch = MaxPitch - OldPitch;

// Calculate change in rotation this frame
FRotator DeltaRotation(0,0,0);
DeltaRotation.Pitch = FMath::ClampAngle(CurrentPitchSpeed * DeltaSeconds, MinDeltaPitch, MaxDeltaPitch);
DeltaRotation.Yaw = CurrentYawSpeed * DeltaSeconds;
DeltaRotation.Roll = CurrentRollSpeed * DeltaSeconds;

// Rotate plane
AddActorLocalRotation(DeltaRotation);