I am experiencing a jerk motion when toggling the bUsePawnControlRotation on my spring arm component. I am currently using the following two function when my character is aiming and would like to know how I can stop it from jerking. I have recorded a video to demonstrate what I have been experiencing. It looks like when I set the bUsePawnControlRotation back to true, it snaps to the mouses position or something like that.
void AThirdPersonCharacter::Aim()
{
//Move the camera boom
if (CurrentWeapon != NULL)
{
CharacterRotation = GetActorRotation();
if (bIsCrouching)
{
GetCharacterMovement()->MaxWalkSpeed = CrouchSpeed;
}
else
{
GetCharacterMovement()->MaxWalkSpeed = AimingSpeed;
}
bIsAiming = true;
CameraBoom->bUsePawnControlRotation = false;
CameraBoom->bDoCollisionTest = false;
}
}
void AThirdPersonCharacter::StopAiming()
{
//Stop aiming and move the camera back
bIsAiming = false;
if (!bIsCrouching)
{
GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
}
CameraBoom->bUsePawnControlRotation = true;
CameraBoom->bDoCollisionTest = true;
FRotator ActorRotation = GetActorRotation();
ActorRotation.Pitch = CharacterRotation.Pitch;
this->SetActorRotation(ActorRotation);
GetCharacterMovement()->bOrientRotationToMovement = true;
}