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.
Before starting
Section titled “Before starting”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:
| Do | As in |
|---|---|
Size 0.3, 0.3, 0.3, Material Neon, then Transform | Exercise 1 |
Motion ▸ Speed 20, Drag 2 | Exercise 1 |
Motion ▸ SpreadAngle 180, Acceleration 0, -40, 0 | Exercise 2 |
Emission ▸ Lifetime 0.4, 0.9 | Exercise 2 |
HUD ▸ Emit box 20 | Exercise 3 |
Procedure
Section titled “Procedure”| Step | Control | Action | Result |
|---|---|---|---|
| 1 | Cloud | Select. 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. |
| 2 | HUD ▸ Emit button | Press | A jagged bolt 20 studs long leaves Cloud straight up, flickers for one second and vanishes. |
| 3 | Properties ▸ Bolt ▸ Target Mode | Set to Seek | The rows under it change. Seek Radius reads 30. |
| 4 | HUD ▸ Emit button | Press | The bolt now runs from Cloud to a point on a nearby surface. With only the floor in reach, it strikes the floor. |
| 5 | Properties ▸ Events | Expand | Four blocks show: On Emit, On Death, On Destruction and On Hit. Each has a switch. |
| 6 | Events ▸ On Hit | Switch on | The rows of the On Hit block appear. |
| 7 | On Hit ▸ Emit ▸ … | Press. Click Sparks in the Explorer. Press Set. | The Emit row shows the path to Sparks. Mode reads AtPosition. |
| 8 | HUD ▸ Emit button | Press | The bolt strikes, and twenty sparks burst from the point where it meets the floor. |
| 9 | Properties ▸ Bolt ▸ Fork Chance and Fork Depth | Enter 0.6 and 1 | No change yet. |
| 10 | Properties ▸ Emission ▸ Lifetime, then Enabled | Enter 0.3, then switch on | Ten bolts a second strike the floor around Cloud, each with branches that come and go, and each throws sparks where it lands. |
| 11 | Properties ▸ Emission ▸ Enabled | Switch off | The storm stops. |
What the steps did
Section titled “What the steps did”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 Mode | The bolt ends |
|---|---|
Directional | A set distance away, along the face chosen in Direction. The distance is Length. |
Point | At the object picked in Target, and it follows that object. |
Seek | On 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.
| Event | The moment |
|---|---|
| On Emit | The particle is newly made. |
| On Hit | The particle has met a surface. For a Seek bolt, it has found its strike point. |
| On Death | The particle’s Lifetime has run out. |
| On Destruction | The 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.
| Mode | The fired emitter appears |
|---|---|
AtPosition | Where the event happened. |
AtCFrame | Where the event happened, turned the way the particle was turned. |
AtSource | At the emitter that owns the event. |
AtTarget | At 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.
If the result differs
Section titled “If the result differs”| Symptom | Cause | Action |
|---|---|---|
| The bolt ends in mid-air | No 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 fires | Target Mode is not Seek. | Repeat step 3. |
| The picker refuses the click | The instance cannot be fired by an event. | Click Sparks. |
The sparks burst at Sparks itself, not at the strike | Mode is AtTarget. | Set Mode to AtPosition. |
| Red text under Mode reads Emits in place | The 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 while | That bolt found no surface. On Hit fires only when a surface is found. | None needed. |
Variations
Section titled “Variations”| Change | Result |
|---|---|
Bolt ▸ Retarget on, Retarget Speed 40, Lifetime 2 | The strike point slides across the floor from place to place, and sparks burst each time it arrives. |
| Properties ▸ Impact ▸ Impact Disk on | A flat glowing disk shows where the bolt lands, for as long as the bolt lasts. |
Target Mode Directional, Direction Bottom, Growth Speed 300 | The bolt is drawn from Cloud downward at 300 studs per second, like a strike coming down. |
| Appearance ▸ Taper, a graph from 1 to 0 | The bolt thins to a point at its tip. |
On the Sparks emitter: Events ▸ On Hit on, Collide Bounce | The sparks bounce off the floor. |
A Light emitter with Emit 1 inside the Lightning RenderTemplate | Every segment of the bolt carries a light, and the bolt lights the scene. |
| New in this exercise | Transform as Lightning. Target Mode. Forks. An event: On Hit, its Emit row and Mode. |
| Done before | A 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 forward | Keep Sparks. |