Hello everyone.
I try to rotate my third person camera and it goes well.BUT when I rotate my character(using control rotation) AND then rotate camera, it starts spinning faster than light.
[Video][1]
Any help appreciated.
Rotate player and camera:
void AMyCharacter::TurnCameraAndCharacter(float Value)
{
if (bTurnCameraAndCharacter)
{
FRotator CameraRot = CameraSpringArm->GetComponentRotation();
CameraRot.Yaw = 0.0f;
CameraSpringArm->SetRelativeRotation(CameraRot);
FRotator NewRot = AMyCharacter::GetActorRotation();
NewRot.Yaw += Value;
this->Controller->SetControlRotation(NewRot);
}
}
Rotate camera:
void AMyCharacter::TurnCameraYaw(float Value)
{
if (bIsTurning&&!bTurnCameraAndCharacter)
{
FRotator NewRot = CameraSpringArm->GetComponentRotation();
NewRot.Yaw += Value;
UE_LOG(LogTemp, Warning, TEXT("turning Yaw"));
NewRot.Roll = 0.0f;
CameraSpringArm->SetRelativeRotation(NewRot);
}
}
void AMyCharacter::TurnCameraPitch(float Value)
{
if (bIsTurning)
{
FRotator NewRot = CameraSpringArm->GetComponentRotation();
NewRot.Pitch += Value;
NewRot.Roll = 0.0f;
CameraSpringArm->SetRelativeRotation(NewRot);
}
}
Character setup:
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;
bIsTurning = false;
//RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
CameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
CameraSpringArm->SetupAttachment(AMyCharacter::GetRootComponent());
CameraSpringArm->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, 50.0f),FRotator(-60.0f, 0.0f, 0.0f));
CameraSpringArm->TargetArmLength = 400.f;//camera distance
CameraSpringArm->bEnableCameraLag = true;
CameraSpringArm->CameraLagSpeed = 3.0f;
//CameraSpringArm->collis
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
Camera->SetupAttachment(CameraSpringArm, USpringArmComponent::SocketName);
}
[1]: