Adding Rotation on Yaw& Pitch rotates the camera X axis aswell / Roll

HI! So I am trying to fix a Free look camera to my first person character.
How I want it to work is when I press ‘Left Alt’ and move on the mouse the camera should rotate in Yaw and Pitch but not in Roll.

How I am doing it atm, I added so I could cap Yaw & Pitch to a sertain radian and as you an see I am not adding anything to Roll. But it is affecting the Roll either way.

Video where I show the rotation of the camera in free look and how it rotates in X- axis / Roll

I am thankful for any help and suggestions :).

I can’t wrap my head around too well, but seeing as you’re programming I’m sure it will be easier. You want to work with quaternions. I believe the default rotation format is eulers. If I say anymore I might explode, good luck!

1 Like

I am wondering if a character movement or camera setting is causing the issue:

// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;

// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...

FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm

I move pawns about my scene with something a little more primitive with AddLocalRotation, so I know the below works (and modifies an attached camera):

.h
UPROPERTY()
FVector2D YawPitch;

And in my source file:

BeginPlay()
{
    YawPitch = FVector2D::ZeroVector;
}

Yaw(float AxisValue)
{
    YawPitch.X = AxisValue * Sensitivity;
}

Pitch(float AxisValue)
{
    if(!IsSouthPaw)
        YawPitch.Y = AxisValue * Sensitivity;
    else
        YawPitch.Y = -AxisValue * Sensitivity;
}

Then I position the pawn based on yaw and pitch:

Tick()
{
    FRotator NewRotation = FRotator(0.0, YawPitch.X * yawFactor, 0.0f);
    Body->AddLocalRotation(NewRotation);
    :
    FRotator NewRotation = FRotator(YawPitch.Y * pitchFactor, 0.0, 0.0);
    Gun->AddLocalRotation(NewRotation);
}

These work as expected. However, I think your issue may be related to a character setting issue.

ok, is the camera attached on the body, for example on the head if you wanted to do a first person camera?

Because my Camera is just loose and not attached. Its placed in the “Head” of my character.
So when I move my camera im not moving my character while holding down Left Alt.
That is only camera movement since I want to make a Free Look for my player.

Thx for your answer! :slight_smile:

I saw you using “bUseControllerRotationRoll = false;” and that fixed it, I needed to disable rotation in roll.
Thank you so much :slight_smile:

1 Like