# How to properly rotate a Pawn (Player Possessed) in Unreal Engine?


// called from 'Tick'
void APlayerPawn::DoRotation(float dt)
{
float mousex = -InputComponent->GetAxisValue(TEXT("MOUSEX"));
float mousey = InputComponent->GetAxisValue(TEXT("MOUSEY"));

FRotator camera_rot = camera->GetRelativeRotation();
camera_rot.Pitch += mousey * LOOK_SPEED * dt;
camera_rot.Pitch = FMath::Clamp(camera_rot.Pitch, -MAX_LOOK_PITCH, MAX_LOOK_PITCH);
camera->SetRelativeRotation(camera_rot.Quaternion());

}


I have a strange problem with my Pawn class. I am simply trying to rotate the root object (in this instance, 'mesh') using mouse movement.

I have this function, and I have tried many variations of the same thing. This one is using AddControllerYawInput from the APawn class. But I have also written it using FQuat quaternions, and also FRotator values. I must have tried at least 5 different approaches that all ended up with the same result (as shown in the GIF clip).

As you can see, I have hardcoded a value instead of using mouse input. I expect the rotation to be pretty much a constant speed. Instead it seems to be on a curve, it gets faster until a point then slows down to zero for a moment and repeats.

I am sure I used this code before in a previous project but unfortunately I lost access to all my old projects so this is all I have.

Edit: For example if I rewrite it like so, the result is the same:

void APlayerPawn::DoRotation(float dt)
{
float mousex = -InputComponent->GetAxisValue(TEXT("MOUSEX"));
float mousey = InputComponent->GetAxisValue(TEXT("MOUSEY"));

//currentYaw += 100 * dt;
//FRotator player_rot = mesh->GetRelativeRotation();
//player_rot.Yaw = currentYaw;
//mesh->SetRelativeRotation(player_rot); <-result=same as GIF

currentYaw += 100 * dt;
FQuat player_quat = mesh->GetRelativeTransform().GetRotation();
FRotator player_rot = player_quat.Rotator();
player_rot.Yaw = currentYaw;
//mesh->SetRelativeTransform(player_rot.Quaternion()); //result=same again
SetActorRotation(player_rot.Quaternion()); //result= same as in gif video

FRotator camera_rot = camera->GetRelativeRotation();
camera_rot.Pitch += mousey * LOOK_SPEED * dt;
camera_rot.Pitch = FMath::Clamp(camera_rot.Pitch, -MAX_LOOK_PITCH, MAX_LOOK_PITCH);
camera->SetRelativeRotation(camera_rot.Quaternion());
}