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.