I’m using five camera shake blueprints on my player character (Forward, Backward, Right, Left, Idle). Whenever the player moves in a direction, it switches to playing a different camera shake using the ClientPlayCameraShake function while simultaneous stopping any other camera shake.
Let’s say that the player moves both forward and right. Is it possible to blend together two different camera shakes?
My second question is how I can get the camera shakes to blend in and out smoothly between transitions. Right now whenever I switch camera shakes, it stops the previous shake immediately, causing the camera to jolt.
My final question is if I can change the ClientPlayCameraShake “Scale” value during runtime. I want the scale to increase based on the player’s speed (so it will increase or decrease in any direction based on if he’s walking/crouching/running). Here is how I have it set up currently:
void APlayerCharacter::MoveRight(float Value)
{
if (CurrentState != nullptr)
{
if (!CurrentState->CanMove())
{
return;
}
}
if (Value != 0.0f)
{
// add movement in that direction
AddMovementInput(GetActorRightVector(), Value);
CameraShakeRight(Value);
}
}
void APlayerCharacter::CameraShakeRight(float Value)
{
APlayerController* MyControllerPointer = Cast<APlayerController>(Controller);
if (MyControllerPointer)
{
Value = Value * (GetCharacterMovement()->MaxWalkSpeed / WalkSpeed);
if (Value > 0)
{
if (!bCameraShakeRightPlaying)
{
if (bCameraShakeLeftPlaying)
{
MyControllerPointer->ClientStopCameraShake(CameraShakeWalkLeft, true);
bCameraShakeLeftPlaying = false;
}
MyControllerPointer->ClientPlayCameraShake(CameraShakeWalkRight, Value);
bCameraShakeRightPlaying = true;
}
}
else
{
if (!bCameraShakeLeftPlaying)
{
if (bCameraShakeRightPlaying)
{
MyControllerPointer->ClientStopCameraShake(CameraShakeWalkRight, true);
bCameraShakeRightPlaying = false;
}
MyControllerPointer->ClientPlayCameraShake(CameraShakeWalkLeft, FMath::Abs(Value));
bCameraShakeLeftPlaying = true;
}
}
}