Following up on my previous question, I decided to create my camera shake for head bobbing motion in code because the solution to that problem was to make CameraBob a UBlueprint variable and completely forgot that the function I’m calling to play the shake requires a UCameraShake variable passed in. Now I’ve hit another brick wall.
Even though my code compiles and all pointers are valid, the camera doesn’t shake and I can’t figure out why. Here’s all the relevant code.
AAdNoctvmPlayerCharacter.h
UPROPERTY()
class UCameraShake* CameraBob;
AAdNoctvmPlayerCharacter.cpp
AAdNoctvmPlayerCharacter::AAdNoctvmPlayerCharacter(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// ...
CameraBob = ConstructObject<UCameraShake>(UCameraShake::StaticClass(), this);
CameraBob->OscillationDuration = 1.f;
CameraBob->LocOscillation.Z.Amplitude = 2.f;
CameraBob->LocOscillation.Z.Frequency = 20.f;
}
void AAdNoctvmPlayerCharacter::PerformCameraBob(float Value)
{
AAdNoctvmPlayerController* PC = Cast<AAdNoctvmPlayerController>(Controller);
if (PC && Value != 0.0f)
{
if (CameraBob)
{
PC->ClientPlayCameraShake(CameraBob->GetClass(), Value);
GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Yellow, TEXT("Camera should be bobbing"));
}
}
}
void AAdNoctvmPlayerCharacter::MoveForward(float Value)
{
if (Value != 0.0f)
{
// ...
PerformCameraBob(Value);
}
}