Making lightning bolts out of bricks from point A to point B

I’ve been trying to create a simple lightning bolt system, which in theory should be fairly simple to create.

Basically, there’s two points. The start/origin point for the bolt, and the end/goal point where the bolt should end roughly. There’s also a set number of parts that are made for the bolt, and each part is rotated slightly so it creates a lightning bolt effect.

This is my attempt, and unfortunately it’s more off than I was hoping for. The parts aren’t branching off of each previous part quite right.

I’m not super sure how to go about this…any information would be greatly appreciated.

I can provide more information if needed, but I hope this gets the point across of what I’m trying to achieve. Thanks!

1 Like

I’ve never tried doing it but someone said you can cast a ray and save positions along the rays, offset the positions then make a part to each position.

1 Like

How about using RodConstraints and making the Attachments in random space from a transparent first Part in space?
Then you only have to worry about the Attachments and I think the Rod lengths will take care of themselves.
If not use a SpringConstraint and set the Diameter to whatever size you want the bolt (smaller toward the end if you want) and Coil diameter to 0. The Length of the Spring should be set to a small number
so it will just stretch between the Attachments.

2 Likes

How I would approach this would be:

  1. Use the previous part’s CFrame and set the new part’s CFrame to that
  2. Move the new part’s center to the end of the old part
  3. Set a random angle using radians
  4. CFrame out from that point
  5. Set the previous part to the new part and repeat

Maybe a bit of code could help my explanation:

local previousPart = workspace:WaitForChild("PreviousPart")
local function createNewPart(previous)
	local newPart = Instance.new("Part")
	newPart.Parent = workspace
	newPart.Color = Color3.fromRGB(255, 0, 0)
	local randomLength = math.random(50, 100)/10 -- Gets random length between 5 - 10
	newPart.Size = Vector3.new(.25, .25, randomLength)
	newPart.Anchored = true
	-- Create new Part

	local randomAngle = CFrame.Angles(math.pi/math.random(6, 12), math.pi/math.random(6, 12), math.pi/math.random(6, 12))
	newPart.CFrame = previous.CFrame * CFrame.new(0, 0, previousPart.Size.Z / 2) -- Set to End of Previous Part
	newPart.CFrame = newPart.CFrame * randomAngle -- Randomize Angle
	newPart.CFrame = newPart.CFrame * CFrame.new(0, 0, randomLength / 2) -- Moves forward by half of part's length
end

createNewPart(previousPart)

Here’s a visual of what you’re accomplishing

5 Likes