Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function makeLightningBolt(a,b)
- local dist = (b.p-a.p).magnitude
- local segments = math.random(math.floor(dist*0.2),math.floor(dist*0.5))
- local boltMdl = Instance.new("Model")
- boltMdl.Name = "LightningBolt"
- local points = {}
- local function slerp(c0,c1,a)
- local c0 = CFrame.new(c0.p) * CFrame.Angles(-math.pi/2,0,0)
- local c1 = CFrame.new(c1.p)
- local startDir = c0.lookVector
- local flightDir = (c1.p-c0.p)
- local totalDist = flightDir.magnitude
- local aheadVec = startDir.unit*totalDist
- return CFrame.new(c0.p + (aheadVec*a)*(1-a)+(flightDir*a)*a)
- end
- local function placeSegment(at)
- local segment = Instance.new("Part",boltMdl)
- segment.Anchored = true
- segment.FormFactor = "Custom"
- segment.Shape = "Ball"
- segment.TopSurface = "Smooth"
- segment.BottomSurface = "Smooth"
- segment.Material = "SmoothPlastic"
- segment.BrickColor = BrickColor.new("New Yeller")
- segment.CFrame = CFrame.new(at.p)
- segment.Size = Vector3.new(2,2,2)
- table.insert(points,segment)
- end
- placeSegment(a)
- for i = 1/segments,1,1/segments do
- local pos = slerp(a,b,i) + Vector3.new(math.random(-5,5),math.random(0,10),math.random(-5,5))
- placeSegment(pos)
- end
- placeSegment(b)
- table.sort(points,function (v1,v2)
- return v1.Position.Y < v2.Position.Y
- end)
- local p
- for _,s in pairs(points) do
- local connector
- if p then
- local off = (s.Position-p.Position)
- connector = p:clone()
- connector.Shape = "Block"
- connector.Size = Vector3.new(2,off.magnitude,2)
- connector.CFrame = CFrame.new(p.Position+(off/2),s.Position) * CFrame.Angles(-math.pi/2,0,0)
- connector.Parent = boltMdl
- Instance.new("CylinderMesh",connector)
- end
- p = s
- end
- boltMdl.Parent = workspace
- return boltMdl
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement