/lightning

Primary LanguageLuaGNU Affero General Public License v3.0AGPL-3.0

Source code for This NPM Package

LightningBeams

Originally created by SamyBlue uploaded by LxtteDev. I did not create this and do not take any credit.

Optimised, lightweight, and highly customisable Lightning Effects for use in Roblox. Can be made into all sorts of special effects.

Features:

  • Layered, moving Perlin noise
  • Uniform disk-point picking for even distribution of control points
  • Can go along a Bezier curve rather than just straight-lines (i.e. Similar to how rblx beams curve)
  • Varying thickness, length, and, transparency
  • Can use ColorSequences
  • Lightning "Sparks" and "Explosion" sub-modules
  • Can smoothly travel as a projectile trying to reach a point

Table of contents

Showcase

ezgif com-gif-maker ezgif com-gif-maker (2) ezgif com-gif-maker (4)

Usage

This section shows the entire API for the main module (LightningBolt) and sub-modules (LightningSparks, LightningExplosion). Default values for properties are in the code.

Example

import LightingBolt from "@rbxts/lightning-beams"

// Create a new bolt with 40 parts
const NewBolt = new LightingBolt({WorldPosition: new Vector3(0,10,0), WorldAxis: new Vector3(0,-1,0)}, {WorldEnd: new Vector3(0,0,0), WorldAxis: new Vector3(0,-1,0)})
local NewBolt = LightningBolt.new(workspace.Attach0, workspace.Attach1, 40)

// Then, update properties to your liking
NewBolt.PulseSpeed = 2
NewBolt.PulseLength = 0.5
NewBolt.FadeLength = 0.25
NewBolt.MaxRadius = 1
NewBolt.Color = new Color3(math.random(), math.random(), math.random())

LightningBolt

LightningBolt.new(Attachment0, Attachment1, PartCount)
Creates a bolt at source Attachment0 which flows into sink Attachment1 with number of parts PartCount

LightningBolt.Destroy()
Cleans up and clears from memory

Appearance Properties

Enabled
Hides bolt without destroying any parts when false
Attachment0, Attachment1
Bolt originates from Attachment0 and ends at Attachment1
CurveSize0, CurveSize1
Works similarly to beams. See https://dk135eecbplh9.cloudfront.net/assets/blt160ad3fdeadd4ff2/BeamCurve1.png
MinRadius, MaxRadius
Governs the amplitude of fluctuations throughout the bolt
Frequency
Governs the frequency of fluctuations throughout the bolt. Lower this to remove jittery-looking lightning
AnimationSpeed
Governs how fast the bolt oscillates (i.e. how fast the fluctuating wave travels along bolt)
Thickness
The thickness of the bolt
MinThicknessMultiplier, MaxThicknessMultiplier
Multiplies Thickness value by a fluctuating random value between MinThicknessMultiplier and MaxThicknessMultiplier along the Bolt

Kinetic Properties

  • Allows for fading in (or out) of the bolt with time. Can also create a "projectile" bolt
  • Recommend setting AnimationSpeed to 0 if used as projectile (for better aesthetics)
  • Works by passing a "wave" function which travels from left to right where the wave height represents opacity (opacity being 1 - Transparency)
  • See https://www.desmos.com/calculator/hg5h4fpfim to help customise the shape of the wave with the below properties:

MinTransparency, MaxTransparency
See https://www.desmos.com/calculator/hg5h4fpfim
PulseSpeed
Bolt arrives at Attachment1 1/PulseSpeed seconds later. See https://www.desmos.com/calculator/hg5h4fpfim
PulseLength
See https://www.desmos.com/calculator/hg5h4fpfim
FadeLength
See https://www.desmos.com/calculator/hg5h4fpfim
ContractFrom
Parts shorten or grow once their Transparency exceeds this value. Set to a value above 1 to turn effect off. See https://imgur.com/OChA441

Color Properties

Color
Can be a Color3 or ColorSequence
ColorOffsetSpeed
Sets speed at which ColorSequence travels along Bolt