Flickering Lights

An example use of a timeline in which we set up a flickering light that also changes color.

Flickering Light

In this example we take a simple point light and we manipulate it such that when a player touches a trigger: the color of the light changes, the light begins to flicker, and after 5 seconds, the light returns to normal.

The nice thing about this example is that we are using three different types of tracks available to timelines.

Timeline.png

The light shown will flicker its brightness and change color.

Setup

The timeline serves 3 primary functions, with a separate track for each:

  1. A Float track (named Brightness) handles animating the brightness. This curve was added from the Content Browser using the Flicker Curve asset.

  2. A Vector track (named Light Color) animates the light's color. This was handled such that the light turns orange at the beginning of the sequence and then returns to white at the end. The curve interpolation was set to clamp, allowing the value to remain constant until the next key.

  3. An Event track (named Trigger Toggle) disables our trigger throughout the duration of the timeline's sequence. Because this is an event track, the values of the keyframes are irrelevant. Wherever the timeline encounters a keyframe, an execution pulse is sent out of the track's associated output pin.

The logic of the network is fairly straightforward. Because we always want the flicker to play from the beginning, our event feeds into Play from Start. However, since we do not want the timeline to be re-triggered during playback, we check the value of a boolean variable whose only purpose is to verify if the timeline is playing.

That variable has a default value of false, meaning we will always play the first time we touch the trigger. So execution from the timeline runs as follows:

  • The result of the Brightness track is multiplied by 20 to give the light more intensity.

  • The color of the light has also changed as the next action.

  • Using the event track, we then trigger a FlipFlop that sets the Is Timeline Playing variable to true. Since this variable is checked whenever someone touches the trigger, we are deactivating the trigger as soon as playback begins.

  • As playback ends, the event track sends another pulse out of the Toggle Trigger event track, which hits the FlipFlop again, turning our boolean back off and thereby reactivating the trigger.

Click for full size

Tags