Skip to content

Exercise 12: Lightning that strikes and sparks

Purpose. To fire a bolt of lightning that strikes the ground, and to burst sparks from the exact spot it strikes.

Nesting, in Exercise 9, fired one effect from another at a fixed moment. Here the second effect must go off where something happens, and that place is not known in advance. The bolt finds its own strike point. An event is how an emitter reports such a moment and fires another emitter at it.

The workspace has a floor that parts can collide with, such as the baseplate. Build two things.

The bolt’s source. One new Part named Cloud, about 15 studs above the floor, with Size 0.4, 0.4, 0.4, Material Neon and a pale colour.

The sparks. One new Part named Sparks, set up as a burst. Every step is one you have done before:

DoAs in
Size 0.3, 0.3, 0.3, Material Neon, then TransformExercise 1
Motion ▸ Speed 20, Drag 2Exercise 1
Motion ▸ SpreadAngle 180, Acceleration 0, -40, 0Exercise 2
Emission ▸ Lifetime 0.4, 0.9Exercise 2
HUD ▸ Emit box 20Exercise 3
StepControlActionResult
1CloudSelect. Press ▾ beside Transform, then Transform as Lightning.Cloud turns invisible. The Properties panel shows the sections of a Lightning emitter. The Emit box reads 1.
2HUD ▸ Emit buttonPressA jagged bolt 20 studs long leaves Cloud straight up, flickers for one second and vanishes.
3Properties ▸ Bolt ▸ Target ModeSet to SeekThe rows under it change. Seek Radius reads 30.
4HUD ▸ Emit buttonPressThe bolt now runs from Cloud to a point on a nearby surface. With only the floor in reach, it strikes the floor.
5Properties ▸ EventsExpandFour blocks show: On Emit, On Death, On Destruction and On Hit. Each has a switch.
6Events ▸ On HitSwitch onThe rows of the On Hit block appear.
7On Hit ▸ Emit ▸ …Press. Click Sparks in the Explorer. Press Set.The Emit row shows the path to Sparks. Mode reads AtPosition.
8HUD ▸ Emit buttonPressThe bolt strikes, and twenty sparks burst from the point where it meets the floor.
9Properties ▸ Bolt ▸ Fork Chance and Fork DepthEnter 0.6 and 1No change yet.
10Properties ▸ Emission ▸ Lifetime, then EnabledEnter 0.3, then switch onTen bolts a second strike the floor around Cloud, each with branches that come and go, and each throws sparks where it lands.
11Properties ▸ Emission ▸ EnabledSwitch offThe storm stops.

A Lightning emitter is made from a Part with Transform as. One particle is one whole bolt with its forks, so an Emit count of 3 means three bolts. The bolt starts at the emitter Part. It takes its thickness from the Part’s size, and its colour and material from the Part.

Target Mode decides where the bolt ends.

Target ModeThe bolt ends
DirectionalA set distance away, along the face chosen in Direction. The distance is Length.
PointAt the object picked in Target, and it follows that object.
SeekOn a surface found within Seek Radius studs. With no surface in reach, the bolt arcs into open air.

Forks are branches. Fork Chance is the chance, from 0 to 1, that each possible branch shows each time the bolt reshapes. Fork Depth 1 allows branches off the main bolt, and 2 allows branches off those branches.

An event is a moment in a particle’s life that the emitter can act on. There are four.

EventThe moment
On EmitThe particle is newly made.
On HitThe particle has met a surface. For a Seek bolt, it has found its strike point.
On DeathThe particle’s Lifetime has run out.
On DestructionThe particle is removed for good, after its Linger if it has one.

Each event can do two things: fire another emitter, and run a script. This exercise uses the first. The Emit row holds the emitter to fire. Mode says where.

ModeThe fired emitter appears
AtPositionWhere the event happened.
AtCFrameWhere the event happened, turned the way the particle was turned.
AtSourceAt the emitter that owns the event.
AtTargetAt its own place in the workspace, as if fired by itself.

The fired emitter keeps its own Emit, Delay and Duration. One difference from nesting: fired by an event, an Emit count of 0 is treated as 1.

SymptomCauseAction
The bolt ends in mid-airNo surface with collisions on lies within Seek Radius of Cloud.Move Cloud nearer the floor, or raise Seek Radius.
The bolt strikes and the On Hit emitter never firesTarget Mode is not Seek.Repeat step 3.
The picker refuses the clickThe instance cannot be fired by an event.Click Sparks.
The sparks burst at Sparks itself, not at the strikeMode is AtTarget.Set Mode to AtPosition.
Red text under Mode reads Emits in placeThe picked emitter cannot be moved to the spot. It is in Animate mode, or it is a kind with no position, such as a Light or a Beam.Pick an emitter made from a Part, in Emit mode.
A bolt strikes and nothing bursts, once in a whileThat bolt found no surface. On Hit fires only when a surface is found.None needed.
ChangeResult
Bolt ▸ Retarget on, Retarget Speed 40, Lifetime 2The strike point slides across the floor from place to place, and sparks burst each time it arrives.
Properties ▸ Impact ▸ Impact Disk onA flat glowing disk shows where the bolt lands, for as long as the bolt lasts.
Target Mode Directional, Direction Bottom, Growth Speed 300The bolt is drawn from Cloud downward at 300 studs per second, like a strike coming down.
Appearance ▸ Taper, a graph from 1 to 0The bolt thins to a point at its tip.
On the Sparks emitter: Events ▸ On Hit on, Collide BounceThe sparks bounce off the floor.
A Light emitter with Emit 1 inside the Lightning RenderTemplateEvery segment of the bolt carries a light, and the bolt lights the scene.
New in this exerciseTransform as Lightning. Target Mode. Forks. An event: On Hit, its Emit row and Mode.
Done beforeA spark burst (Exercises 1, 2 and 3). Transform as (Exercise 11). The Emit button (six times). Lifetime and Enabled (Exercises 1 and 2). Picking an instance (Exercise 7).
Carried forwardKeep Sparks.