[TIP] Looking Up and Down with Camera Roll

If your camera has a roll other than zero and you want to look up in your view rather than along the world Z axis, here’s how:

We are using a rotation matrix. To elaborate, we are rotating our input Vector2D by (θ) which is our camera roll angle. After rotating, we add yaw and pitch input to the controller in alignment with the newly rotated values.

void ACamera::Look(const FInputActionValue& Value)
{
	// input is a Vector2D
	FVector2D LookAxisVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		float X = LookAxisVector.X;
		float Y = LookAxisVector.Y;

		//Roll angle
		FRotator ActorRotation = GetActorRotation().GetNormalized();
		float Theta = FMath::DegreesToRadians(ActorRotation.Roll);
		
		// Calculate cos and sin of the angle Theta
		float CosTheta = FMath::Cos(Theta);
		float SinTheta = FMath::Sin(Theta);
		
		// Compute the new coordinates
		float NewX = X * CosTheta - Y * SinTheta;
		float NewY = X * SinTheta + Y * CosTheta;
		
		// add yaw and pitch input to controller
		AddControllerYawInput(NewX);
		AddControllerPitchInput(NewY);
	}
}

I am open to better solutions if you have one.
Hope you can adapt this to your project without too much effort. Thanks for reading.

P.S. I am using this in my PhotoMode project: GitHub - egementon/PhotoModeProject: C++ Advanced Photo Mode inspired by games like Hellblade II