Build a Dynamic Lightning Effect
In this free tutorial, we'll build a complete lightning effect using Rive scripting and the AI agent. Fast-paced and hands-on, end-to-end in one sitting.
In this free tutorial, we'll build a complete lightning effect using Rive scripting and the AI agent. Fast-paced and hands-on, end-to-end in one sitting.
Goal: In this step we'll get the simplest version of a lightning bolt working: a straight line that draws on click. We start simple to verify the script wires up before adding the zigzag, glow, and flicker.
Setup: Create a 500x500 artboard. Open the AI agent panel and set the model to Smart.
How:
Creates a Node Script with three inputs (width, height, speed)
Draws a white line from a random X at the top to wherever you click
Animates with trim path and fades out
Adjust the result
Goal: In this step we'll turn the straight line into a zigzag shape that looks like real lightning. Same inputs, same animation, just a sharper visual.
How:
Breaks the line into connected segments that shift left and right
Adds a lightningRandomness input to control the chaos
Start with a value around 20. Too high and it goes wild.
Adjust the result
Goal: In this step we'll add the visual that makes lightning feel real: color, thickness, and a soft glow behind the bolt.
How:
Renders two strokes: a soft glow behind and a sharp core on top
Adds inputs for color, thickness, feather, glow color, and opacity
After running this, lower the lightningFeather and raise the lightningGlowOpacity to make the glow visible.
Adjust the result
Goal: In this step we'll add a screen flash when the bolt strikes, so the whole scene reacts and the lightning lands harder.
How:
Creates a full-artboard rectangle that briefly brightens the screen
Triggers with a short delay after the bolt starts drawing
Flickers once, then fades out
The flash appears behind the bolt so the lightning stays visible.
Goal: In this step we'll add a tiny flicker to the bolt as it appears, the kind of subtle energy that makes lightning feel alive.
How:
Regenerates the zigzag shape a few times during the animation
Each variation uses slightly different offsets
After a short moment, settles and fades out
After this step, play with the inputs. Try different randomness, thickness, and glow combinations until it feels right.
What we built:
A dynamic zigzag line that draws on click
Customizable color, thickness, and glow
A screen flash triggered by each strike
A flicker animation that makes the bolt feel alive
You can drop this script into any scene. In the tutorial, we placed it in a storm scene with clouds and a rain script. In the scripting course, this same lightning becomes a weapon system for a spaceship. Dynamic cannon positions, fuel cost per shot, and a full game loop.