Mini tutorial: Make a configurable custom camera shake using timeline

Here is a way that you can use a timeline to create a configurable camera shake event.

Is this better or worse than using Unreal’s camera shake class? Probably just a bit different, but I find it a little less cumbersome overall and easier to get exactly the results that I want without as much time spent tweaking.

The idea is that we create an assembly line that intakes Curve Assets and spits out a camera shake.

What you’ll need:

  • Reference to the desired camera
  • a Timeline
    • Reference to the timeline component (this is created automatically when you add the timeline. Check in the variables category “Components” to find it.
  • Vector curve assets
    • Create curve asset in content browser, set it to Vector type

Step by step:

The Main Event
image
The event is what you will call whenever you want to play a camera shake. You’ll pass in a curve asset to describe both Rotation and Location. You can also pass in a float for the Rate and you could add a float for the strength as well.

The Timeline
image

Add a timeline and give it two vector tracks:


You don’t need to do anything except create and name the tracks!

The actual curve data we will pass in by using a reference to curve assets.

Note that when you create a timeline, it is added as a component automatically:
image

You will use this reference to pass in data to the timeline and configure it.

The inputs - Curve Assets:

Create rotation and location curves to define your shake. Set the timeframe to be about average of what you expect - but you can configure the play rate so its not necessary to get it perfect. You can also adjust the scale at runtime, so don’t waste too much time at the beginning. The idea is to give ourselves a few variables to tweak so that we can iterate through playtesting without having to jump around to tons of different assets later.
image

Tip: Use stacked view mode to avoid selecting multiple curves if necessary

Reference to the Curve Assets. You could store this in a data asset. I use a manager located either on game instance or player controller to hold config data like this. That way when I want to tweak the game during playtesting, I dont need to open up many classes. Everything is in one place.
image

Bring it all together

Timeline drives camera movement

Feed inputs to timeline and run it from the Main Event

Call it with configurable data

Be aware that you can set timelines to loop, so you may also use this for ongoing camera shakes, not just one-off events. But you’ll probably want separate events to toggle it off to keep short, maintainable code.

2 Likes