FMath::Lerp doesn't enfore shortest arc for Pitch

As title suggest, I am using FMath::Lerp to interpolate between two quats. However, I still face the Rotator Pitch bug described here.

I though I could avoid the bug by performing my rotation calculations through quaternions, but apparently that is not the case.

Any help in this case would be greatly appreciated.

    FVector _CrosshairLocation = CrosshairComponent->GetComponentLocation();
	FVector _ParentLocation = RootComponent->GetComponentLocation();

	FVector _Dir = (_CrosshairLocation - _ParentLocation);
	_Dir.Normalize();
 	
 	FQuat _DirQuat = FQuat(_Dir.Rotation());
 	FQuat _RootQuat = RootComponent->GetComponentRotation().Quaternion();
 	FQuat _ResultantQuat = FMath::Lerp(_RootQuat, _DirQuat, RotationSpeed * DeltaSeconds);	
	
	FRotator _ResultantRot = _ResultantQuat.Rotator();

If I understand you correctly, you want to use the RLerp function from the KismetMathLibrary (see docs). The link you posted is broken…

I tried using the blueprint Rlerp function and had the same issue. The RLerp function calls the FQuat::Slerp so, I tried to swap out FMath::Lerp and use FQuat::Slerp which again causes the same problem.

Fixed the link and also added the current code to the base question.

Just posting this for other people that may stumble upon the same issue as OP.

I’ve had a similar problem with finding the shortest rotational path and came to find this in Epic’s UE-4.15 Engine:

					FRotator NewRotation;
					// If we are done just set the final rotation
					if (bComplete)
					{
						NewRotation = TargetRotation;
					} else {
						// We want the shortest path 
						FQuat AQuat(InitialRotation);
						FQuat BQuat(TargetRotation);

						FQuat Result = FQuat::Slerp(AQuat, BQuat, BlendPct);
						Result.Normalize();
						NewRotation = Result.Rotator();
					}
					TargetComponent->SetRelativeRotation(NewRotation, false);

Maybe this has some use for someone else out there.

Source file: C:\Program Files\EpicGames\UE_4.15\Engine\Source\Runtime\Engine\Private\InterpolateComponentToAction.h