Download

Use Pawn Control Rotation disabled issue

Hello all! I am working on some fancy camera movement, and I ran into problems after disabling “Use Pawn Control Rotation”. When disabled and I adjust the pitch using the mouse, the camera seems to be rotated as if it’s origin was the very back of the camera component gizmo. When it’s enabled, the camera seems to be being rotated as if it’s origin is the center of the gizmo which is what I want. Here are two videos along with some the code to help explain the issue better:

Camera->Use Pawn Control Rotation: True
Use Controller Pitch Input: True
Use Controller Yaw Input: True
Use Controller Roll Input: True

Camera->Use Pawn Control Rotation: False
Use Controller Pitch Input: True
Use Controller Yaw Input: True
Use Controller Roll Input: True



        if (Controller == nullptr || !AdvancedCameraMovement)
		return;

	if (!GetCharacterMovement()->IsMovingOnGround() || !bIsMoving || bIsCrouching)
	{
		Camera->SetRelativeLocation(FMath::VInterpTo(Camera->RelativeLocation, FVector(0, 0, BaseEyeHeight), delta, 10));
		Camera->SetRelativeRotation(FMath::RInterpTo(Camera->RelativeRotation, FRotator::ZeroRotator, delta, 10));
		return;
	}

	FVector velocity = FRotationMatrix(GetControlRotation()).InverseTransformVector(GetVelocity());

	float bobZ = FMath::Sin(Delta * (velocity.Size() * (PI / 180)) * 2) * (bIsSprinting ? WalkingAmplitude * 2 : WalkingAmplitude);
	
	Camera->SetRelativeLocation(FMath::VInterpTo(Camera->RelativeLocation, FVector(0, 0, BaseEyeHeight + bobZ), delta, 20));
	Camera->SetRelativeRotation(FMath::RInterpTo(Camera->RelativeRotation, FRotator(0, 0, velocity.SafeNormal().Y * (bIsSprinting ? LeanAmount * 2 : LeanAmount)), delta, 10));


In both videos, I start by moving to show which one has my custom camera movement, then I look down to show the difference. Notice that with “Use Pawn Control Rotation” set to false, the camera appears to be closer to the ground when I look down. Also, with “Use Pawn Control Rotation” set to true, I cannot adjust the roll of the Camera. Any help? How would I fix this? Is there a better way to do this? Thanks!

Bump! :smiley: Anyone have a solution?

Camera management can be kind of a nightmare with all the different classes involved, so it’s hard to tell what’s going on without being able to inspect some values at runtime. If you haven’t been using it, do try the displayall console command. It lets you display the current value of a UProperty, i.e.:


displayall PlayerController ControlRotation
displayall CameraComponent RelativeLocation
displayall CameraComponent RelativeRotation

Your problem seems to stem from the order in which transforms are applied, it’s as if rotation is being applied before translation. So when the camera is level, this is fine, but when the camera is angled downwards, then BaseEyeHeight (+ bobZ) moves your camera forward instead of upwards.

Changing the order of the SetRelativeLocation/SetRelativeRotation calls won’t do anything, FTransform stores its components separately so unlike matrix multiplication, order doesn’t matter. I can never remember off hand which order the transform components are applied in, but I don’t believe it’s suppose to be rotation -> translation. Inspect all the transforms being applied to the camera component, and if necessary, add an extra scene component to better control the order of the transforms.

-Camille