Is there some kind of bug with 5.5 engine or i mess up my code? I was trying to do camera movement in enhanced input system c++, but the game runs on 60 fps, and suddenly i got 30 fps drop randomly. Why is that happening?
My camera movement:
void APlayerPawn::Tick(const float DeltaTime)
{
Super::Tick(DeltaTime);
// Smoothing Camera Moving, Rotating, Zooming.
SetActorLocation((FMath::VInterpTo(
GetActorLocation(),
CameraLocationDesired,
GetWorld()->GetDeltaSeconds(),
CameraMoveInterpolation)));
SetActorRotation((FMath::RInterpTo(
GetActorRotation(),
CameraRotationDesired,
GetWorld()->GetTimeSeconds(),
CameraRotationInterpolation)));
SpringArmComponent->TargetArmLength = FMath::FInterpTo(
SpringArmComponent->TargetArmLength,
CameraZoomDesired,
GetWorld()->GetDeltaSeconds(),
CameraZoomInterpolation);
}
//=================================================================================================================
// Input Setup
//=================================================================================================================
void APlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
if (const APlayerController* PlayerController = Cast<APlayerController>(GetController()))
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
{
Subsystem->AddMappingContext(MappingContext, 0);
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent))
{
EnhancedInputComponent->BindAction(CameraMoveAction, ETriggerEvent::Triggered, this, &APlayerPawn::CameraMove);
EnhancedInputComponent->BindAction(CameraRotateAction, ETriggerEvent::Triggered, this, &APlayerPawn::CameraRotate);
EnhancedInputComponent->BindAction(CameraZoomAction, ETriggerEvent::Triggered, this, &APlayerPawn::CameraZoom);
EnhancedInputComponent->BindAction(CameraCenterAction, ETriggerEvent::Triggered, this, &APlayerPawn::CameraCenter);
}
}
}
}
//=================================================================================================================
// Camera Management
//=================================================================================================================
void APlayerPawn::CameraMove(const FInputActionValue& InputActionValue)
{
FVector AxisValue = InputActionValue.Get<FVector>();
AxisValue.Normalize();
CameraLocationDesired = (GetActorForwardVector() * (AxisValue.X * CameraMoveSpeed)) +
CameraLocationDesired +
(GetActorRightVector() * (AxisValue.Y * CameraMoveSpeed));
}
void APlayerPawn::CameraRotate(const FInputActionValue& InputActionValue)
{
const float AxisValue = InputActionValue.Get<float>();
CameraRotationDesired = UKismetMathLibrary::ComposeRotators(
CameraRotationDesired,
FRotator(0.f, AxisValue * CameraRotationSpeed, 0.f));
}
void APlayerPawn::CameraZoom(const FInputActionValue& InputActionValue)
{
const float AxisValue = InputActionValue.Get<float>();
CameraZoomDesired = FMath::Clamp(
AxisValue * CameraZoomSpeed + CameraZoomDesired,
CameraZoomMin,
CameraZoomMax);
}
void APlayerPawn::CameraCenter()
{
CameraComponent->SetRelativeLocation(FVector(0, 0, 0));
CameraLocationDesired = FVector(0, 0, 0);
CameraRotationDesired = FRotator(0.f, 0.f, 0.f);
}