Download

Actor won't rotate

How come this call (binded to mouse X axis) is not making my character turn around?



void AMyCharacter::CameraYaw(float const Value)
{
    SetActorRelativeRotation(FRotator(0.f, Value, 0.f));

    UE_LOG(LogTemp, Warning, L"Current actor rotation: Pitch %f, Yaw %f, Roll %f", GetActorRotation().Pitch, GetActorRotation().Yaw, GetActorRotation().Roll);
}


The numbers in the log increase when I move the mouse, but as soon as I stop, they start to drop until everything is zeroed out

Same resoult with this call:



void AMyCharacter::CameraYaw(float const Value)
{
    SetActorRotation(GetActorRotation() + FRotator(0.f, Value, 0.f));
}


Can you show the constructor code for the Actor, could be that your mesh or whatever you are using is not attached to the rootcomponent, hence the actor rotates but not the component.

The mesh is attached to the capsule component, but that should be attached to the root I think. I am inheriting from the Character class



AMyCharacter::AMyCharacter()
{
    // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    Speed = 8.f;

    StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>("StaticMesh");
    StaticMesh->SetupAttachment(GetCapsuleComponent());

    SpringArm = CreateDefaultSubobject<USpringArmComponent>("SpringArm");
    SpringArm->SetupAttachment(RootComponent);
    SpringArm->SetRelativeRotation(FRotator(-38.f, 0.f, 0.f));
    SpringArm->TargetArmLength = 500.f;
    SpringArm->bEnableCameraLag = true;
    SpringArm->CameraRotationLagSpeed = 1.f;

    Camera = CreateDefaultSubobject<UCameraComponent>("Camera");
    Camera->SetupAttachment(SpringArm);
}


Also if I reload my character blueprint from the editor, this is the output message