AddControllerPitchInput not working even though bUsePawnRotation == true

Hello!

I’ve written a class inheriting from the ACharacter class and I’m at the moment
trying to make it so that my actor aligns its pitch to the ground.
My method is to cast a ray from my actor location down along the actors up vector
and then using the impact normal to calculate the vector representing the current angle.

The method returns a float value that I then want to use as a part of the param in the AddControllerPitchInput method.
As mentioned in the heading this has no effect. I searched the web for an explanation and found out (without a reason why)
that ticking the attribute bUsePawnRotation in both my springArm and camera would solve the issue.

I set both of the attributes to true in the class constructor but it had no effect. After that I started to doubt
my linear algebra. To see if my calculations was the problem I used my values in the method SetActorRotation
instead. This pitched my character to the angle I was seeking but with the stuttering issues that comes with
the mentioned method.

Any ideas of where to go from ?

Did u try turn on or off the “Inherit Pitch” property of the spring arm or camera?

First of all.

What I mentioned about bUsePawnRotation not having an effect wasnt really true.
It seems as if the settings didnt update properly before I wrote this topic. The effect
I then realised it had was not the one I was looking for at all.

If I’ve understood it correctly bUsePawnRotation fixes the camera and/or the spring arm
to the character rotation. This makes all of my movement methods useless and just
completely messes up the controls I’ve set up for my camera.

I tried to combine this setting with others and never got the effect I was looking for :confused:

As mentioned in my first post I’m looking to pitch my character to align it to the ground.
Since I’m using AddControllerYawInput(float) to yaw my character I figured the pitch version
would work just as well.

I dont see how camera or spring arm settings would change the outcome. These components
are children to my mesh and should (if I’m not totally lost) follow along.

Is there anyone out there who completely understands how these components and methods
relate to eachother and have an explanation why AddControllerPitchInput(float) doesn’t work?

Tyvm Fallonsnest for trying to help :slight_smile:

Personally im using custom method for calculate the pitch/yaw of the character and use animation aimoffsets in the animation blueprint with the Pitch/Yaw values of the character to move the head of the character, then attach the sprint arm/cameras directly to the head.



void ASwatCharacter::UpdateAimOffsets(float DeltaTime)
{
    // Save the current aim pitch and yaw
    float SavedAimPitch = AimPitch;
    float SavedAimYaw = AimYaw;

    // Update the aim offset
    FRotator ControlRotation = GetControlRotation();
    FRotator ActorRotation = GetActorRotation();
    FRotator DeltaRotation = ControlRotation - ActorRotation;
    DeltaRotation.Normalize();

    // Interpolate the current and new aim offsets for smoothing
    FRotator CurrentAimOffset(AimPitch, AimYaw, 0.0f);
    FRotator UpdatedAimOffset = FMath::RInterpTo(CurrentAimOffset, DeltaRotation, DeltaTime, 15.0f);
    AimPitch = UpdatedAimOffset.Pitch;
    AimYaw = UpdatedAimOffset.Yaw;

    // Notify the server about the new aim offset
    if (Role < ROLE_Authority && (AimPitch != SavedAimPitch || AimYaw != SavedAimYaw))
    {
        //TODO: This might give some network overhead, see if we can replicate this trough the movement component
        //        see RemoteViewPitch (how its set and replicated)
        ServerSetAimOffset(AimPitch, AimYaw);
    }
}


Thank you for sharing!

I’m going to try and interpret your code and see where it gets me :slight_smile:

I’m guessing this is in first person?

My character is a Lynx viewed in third person. Hence the focus on pitching in slopes etc :slight_smile:

My character class support both first and third person, where i have 1 camera attached “inside” the head and a second camera with a spring arm, so i can switch view.
So both the FPS camera and TPS camera are attached to a socket on the character skeleton.

I will check when i get home from work, i have some 3the person project where i can use the mouse to drag the camera around the character, zoom in/out and stuff, that might be more usefull

Just drooping in in a old project i used.


PlayerCameraManager->bUseClientSideCameraUpdates = true;

And i used this of the Shooter Example game…


FRotator GetAimOffsets() const
{
            const FVector AimDirWS = GetBaseAimRotation().Vector();
            const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(AimDirWS);
            const FRotator AimRotLS = AimDirLS.Rotation();

            return AimRotLS;
}

That is all i used to replicate aim angel.
Its been a while since i have been working with UE 4 so hope it helps.

Worth noting i only used 1 camera for both views i just relocated the camera.

EDit: these settings also may be relevant.


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

    // Configure character movement
    GetCharacterMovement()->bUseControllerDesiredRotation = true; // Character Mesh rotated with controller rotation input.
    GetCharacterMovement()->bOrientRotationToMovement = false; // Character moves in the direction of input...    
    // Create a camera boom (pulls in towards the player if there is a collision)
    CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

    // Create a follow camera
    FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm