How should I go about making a lightning?

Recently, I wanted to make a sort of lightning made of parts with the help of a script. I’ve read a couple of topics with regards to the issue but I am still extremely confused on how I should do it.

Questions:
1: How should make it such that all the parts of the lightning are connected to one another (No gaps between parts)?

2: What is the method that I should be using? (Should I start from a top brick and work to the bottom)

3: How can I make it such that there are branches branching out from the lightning?

How do I change from a straight lightning

To one that branches out?

4: Other things I should take note.

4 Likes

I made a lightning tutorial a few years ago, should be a decent basis for you.

As regards splitting off streaks of lightning, you’ll want to take note of every point in the lightning pieces, and at some random interval - create a new lightning streak from that point.

Let me know if you need a hand and I’ll get back to you later (need to go for now).

13 Likes

That’s very interesting. I’ve watched the video but still confused about:

local too = from +  - (from - too).unit*step + offset

Why do you multiply (from - too).unit by step?

Also is too referring to Workspace.Part2.Position or the new part that is being generated?


On line 37, when lerping why do you set alpha to 0.5? You mentioned in the video that it moves the lightning part to half the distance between Part1 and Part2 but how does that work?

Lerp takes two Vector3 (position, size, direction, etc) values and transitions them based on the ‘alpha’ - in this case as you mentioned on line 37, ‘0.5’ is the alpha.

Here’s an example:
pos0 = Vector3.new(0,0,0)
pos1 = Vector3.new(0,1,0) – One stud above 'pos0

position = pos0:Lerp( pos1, 0 )
-- position would be equal to  Vector3.new( 0, 0, 0 ) - as the alpha is set to '0' (closer to 'pos0').

position = pos0:Lerp( pos1, 0.5 )
-- position would be equal to  Vector3.new( 0, 0.5, 0 ) - as the alpha is set to '.50' (in between 'pos0' and 'pos1')

position = pos0:Lerp( pos1, 1 )
-- position would be equal to  Vector3.new( 0, 1, 0 ) - as the alpha is to '1' (closer to 'pos1')

You can test this in Studio’s Command bar with this code:

alpha = 0 print( Vector3.new(0,0,0):Lerp(Vector3.new(0,1,0), alpha))
Just change the alpha.




As for;
local too = from + -(from - too).unit*step + offset

Old habits die hard - Sorry.
from + -(from - too) -- sets which direction the new lighting streak will go.
It can be simplified to just: from + (too-from)

.unit converts a vector3 into a small format:
Vector3.new(0, 100, 0).unit = Vector3.new(0, 1, 0)

This is multiplied by ‘step’ which essentially acts like the alpha mentioned above - except it transitions between 0 and the maximum distance the lightning tranvels.

The offset is another Vector3 value that simply pushes the position we got above out of line slightly, which gives the chaotic ‘lightning’ effect.

Apologies for the clumsy tutorial, I’ve never been one for wording. Hahaha.

1 Like

I used this method to get some really nice results

http://drilian.com/2009/02/25/lightning-bolts/

2 Likes

@Vineyard Thanks for the share, really useful way of making lightning.


I’ve still got another problem:

Whenever make an offset to turn the lightning part, I can’t make the part stay at a particular spot. Here’s an example:

Original Lightning Bolt:


[Original Lightning Bolt Position. Right Part is the lightning bolt.]

Intended Final Position of Lightning Bolt:

I want the part to rotate about the larger part to the left.

What Actually Happens when you rotate using script:


[Lightning Part gets rotated about its centre.]

Does anyone have a solution to this problem?

You would want to rotate it about that block sitting there.

You could probably do something like:

bolt.CFrame = thatBlock.CFrame * CFrame.Angles(yourAngle)* CFrame.new(0,0,bolt.Size.Z/2)

Granted you may need to tweak a few things to make that work how you would like it to.

1 Like