Camera Bob/Shake

Hi,

I’m trying to get a camera bob effect when the player is moving forward and having some trouble. I have a CameraShake blueprint that should simulate a bobbing effect with a hook from my C++ MoveForward function but it’s not working and I don’t know why. The log calls just fine so I assume there may be something missing from the blueprint maybe?

QUBECharacterPlayer.cpp:

void AQUBECharacterPlayer::MoveForward(float Value)
{
	if ((Controller != NULL) && (Value != 0.0f))
	{
		FRotator Rotation = Controller->GetControlRotation();

		// Limit pitch when walking or falling
		if (CharacterMovement->IsMovingOnGround() || CharacterMovement->IsFalling())
		{
			Rotation.Pitch = 0.0f;
		}

		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(0);
		AddMovementInput(Direction, Value);

		// Camera bob -- currently not working :/
		if (CameraBob != NULL)
		{
			AQUBEPlayerController* PC = Cast(Controller);
			if (PC != NULL && PC->IsLocalController())
			{
				PC->ClientPlayCameraShake(CameraBob, 1);
				UE_LOG( LogChar2, All, TEXT( "--- Camera Should be Bobbing! --- ---" ));
			}
		}
	}
}

Thanks!

Jon

Hi Jon,

I spent a little time looking at this and found that camera modifiers are not being applied properly in most cases. I’ve submitted a fix for this. As a workaround in the meantime, you can set the following flag on your camera

bAlwaysApplyModifiers = true;

This will force modifiers to be applied in all instances, which is how ShooterGame got around this issue as well.

Sorry for the trouble!
Jeff

Thanks Jeff that worked! :smiley:

Thanks!!

Jon

Hi

I’m still having some trouble with playing camera shakes for some reason.

I’ve hooked up the Q key to fire off this simple function to test a camera shake but I’m not getting a shake. The log fires just fine so I know thats working. Are there any #includes I need to add for camera shakes to work?

void AQUBECharacterPlayer::Shake()
{
	if((Controller != NULL))
	{
		AQUBEPlayerController* PC = Cast(Controller);
		if (PC)
		{
			PC->ClientPlayCameraShake(BobCameraShake, 1);
			UE_LOG( LogChar2, All, TEXT( "--- Camera Shake!!!! --- ---" ));
		}
	}
}

Thanks!

Jon

Should I create a new camera actor for this in code too?

Thanks

Jon

That shake data looks like it should produce noticeable motion. The first thing I would check is to verify that BobCameraShake is populated correctly and has the values that you think it should.

I’ll dig in a little more here as well to make sure the system is working as intended.

Cheers!
Jeff

Hi Jeff,

Thanks for looking into this for me. Much appreciated.

Is there way I can set the oscillation values in code to see if that makes a difference?

Cheers,

Jon

If you just want to inspect the values, use your debugger and set a breakpoint in that function. Depending on your IDE, you can probably modify the values in-memory if you like, just to experiment.

To set up a CameraShake in code, create a new CameraShake object and hold a pointer to it (in a UProperty so it doesn’t get GCed), then set the values as you see fit. As a quick example, check out the AShooterPickup constructor in ShooterGame, where it creates a UParticleSystemComponent.

-Jeff

Hey Jeff,

I’ve been trying to create camera shakes but still having issues getting any kind of shaking.

I’ve tried creating a test in blueprint to see if it’s just my code that’s not working and found that even in blueprint I cannot get a shake to work. I’ve also tested this in ShooterGame and still unable to get a shake which I find odd as ShooterGame has a couple of CameraShakes fire off in code.

What could I be doing wrong?

Thanks,
Jon

Try cranking your “outer radius” up. Something crazy like 10,000

Hey Alexander, thanks for the reply.

So this now works with ShooterGame but not with my custom project. Not sure why, any ideas?

I’ve tried up to 100,000 in the outer radius too with no effect.

Thanks!!

Jon

In your screenshot I see you’ve set the epicenter to 0,0,0. Try setting that to your camera’s world location.

Hi Jonathan,

Your code looks as if it will call ClientPlayCameraShake every frame that you are moving forward. I suspect your shake has bSingleInstance=true, which means it will restart the shake every frame and appear to have no effect.

Try using a looping shake, then starting it when you start moving and stopping it when you stop.

Cheers!
Jeff

Thanks Jeff, I’ll take a look!