Random Lighning

Here goes my first post!



I had this idea for randomly generating animated lightning-style effects, and I wanted to know if 1) anyone here has tried it, and 2) if it seems like it would work. It relies upon defining a complex path for a particle, and sending a continuous stream of particles down it.



The idea is this: define a ray between two points (Note: this is not the path). Then, at random points down the ray, make perpendicular smaller rays with variable length and random rotation around parent. So, you have this, or rather something much more complex (and 3d):

    |        |

—/-----/


/--
          |        |

Then, define the path by connecting lines from each "tip" to the next. You should gain a suitably random appearing stroke that has a more or less straight path, and sending particles down it will make it look like lightning.

The animation part comes from setting a max distance the points on the line can move - the rotation and length down the ray change so that it retains its basic shape while still looking active.

The biggest thing I like about this is that it's customizable: you can easily change the particle, the width of the stroke (by allowing the offshoots bigger lengths), the "jaggedness" (just make the offshoots more common), increasing the speed at which it animates, and so forth. Also, if in a game you use if as a damage mechanic, it's much more realistic: give each particle a damage amount, and damage is dealt according to time of contact and strength of charge, rather than being a one hit deal.

Heres my implementation:

http://www.jmonkeyengine.com/jmeforum/index.php?topic=5616.0



I tried rotating the entire lighting strike around instead of making a new one and some angles were a bit familiar, but that was staying in the same place. I dont know what yours would be like…



If you like the Diablo1 chain lightning style effect, just have a randomly rotating and sizing line at a node location and move a couple of them along… The links between are optional.