How to make 2d Fireworks?

How would I create 2d Fireworks?

This is what I got so far:
fireworks.rbxm (5.0 KB)

If you test the game, you can see that the sparkles move to 4 different corners, rather than in a circular spread.
How would I randomly spread the Sparkles in a circular spread?

What do you mean by a circular spread? Do you mean like the frames go around in a circular motion or like all around?

basically minecraft fireworks, how it explodes in a ball.

1 Like

Here’s how I’ve modified your function. Each particle calculates a random angle between 0 and 360 degrees and a random amount to move between min and max as a percent of the screen width.

local ts = game:GetService("TweenService")
local info = TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
+ local absoluteSize = script.Parent.AbsoluteSize
+ local aspectRatio = absoluteSize.X / absoluteSize.Y

function firework(amount)
	local min = 150
	local max = 250

	local rX = math.random(0, 1000)/1000
	local rY = math.random(0, 1000)/1000

	local light = script.Light:Clone()
	light.Parent = script.Parent.Area
	light.Position = UDim2.new(rX,0,rY,0)
	spawn(function() 
		local tween = ts:Create(light, info, {ImageTransparency = 1})
		tween:Play()
	end)
	for i = 1,amount do
		spawn(function()
			local spark = script.Sparkle:Clone()
			spark.Parent = script.Parent.Area
			spark.Position = UDim2.new(rX,0,rY,0)

+			local angle = math.rad(math.random(0, 360))
+			local mag = math.random(min, max) / 1000
+			local newPos = UDim2.new(rX + math.cos(angle) * mag, 0, rY + aspectRatio * math.sin(angle) * mag, 0)

			spark:TweenPosition(newPos, "InOut", "Quad", .5, true)
			wait(.6)
			local tween = ts:Create(spark, info, {ImageTransparency = 1})
			tween:Play()
		end)
	end
end

wait(5)
for i = 1,1 do
	spawn(function() firework(25) end)
	wait(.5)
end
3 Likes