Tutorial on making Spreading object/projectile or Cone AOE

I made this spreading attack thing for around a month ago, so i decided to spend my next hours to adjust my scripts and make this QUICK TUTORIAL post for community resources and wish to help beginner developers who are struggling making something similar to this!

Here is the result if you done everything correctly in this tutorial :

Code With Commentaries

Before beginning the tutorial, you will need to answer yourself these following questions :

AmountPerStages = number
Controls how many object/projectile per stages
for the best result, please use a single number like 1, 2, 3… etc. Avoid using rational number like 0.75, 0.5, 0.25, … etc, you can still use those rational number but the result will not as good as a single number

StagesBetweenDistance = number
Control how many stages will spawn


1 Stage = 1 Part in the picture above
For the best result, please use a single number, avoid using rational number for Stages count

PointsDistance = number


Distance between the begin and the end of the array
You can choose whatever number you like for this

Requirement : :point_down:

local Amount = 0
local Stage = StageBetweenDistance
local Distance = PointsDistance

1st Step : You need a beginning point and a end point which are basically just 2 parts. Note : 2 points should line up in a straight line with each other and face each other

local Startpart = Instance.new("Part")
Startpart.Size = Vector3.new(1,1,1)
Startpart.CanCollide = false
Startpart.Anchored = true
Startpart.Position = START_LOCATION

local EndPart = Instance.new("Part")
EndPart.Size = Vector3.new(1,1,1)
EndPart.CanCollide = false
EndPart.Anchored = true
EndPart.CFrame = Startpart.CFrame * CFrame.new(0,0,-Distance)

2nd Step : Execute a code that creates a part for each stages between the beginning and the end

for StageCount = 0, Stages do 
	local part = Instance.new("Part",workspace)
	part.Name = "Part"
	part.Size = Vector3.new(1,1,1)
	part.CanCollide = false
	part.Anchored = true
	part.CFrame = Startpart.CFrame * CFrame.new(0,0,((Startpart.Position - EndPart.Position).Magnitude/Stages) * StageCount)
	Amount = Amount + AmountPerStages
end

3rd Step : Which is a important step for displaying the object/projectiles, i’d prefer to make 2 wings separately because it’s simpler and more customizable

	for i = 1, Amount do 
		local RightWing = Instance.new("Part",workspace)
		RightWing.Name = "Right Wing"
		RightWing.Size = Vector3.new(1,1,1)
		RightWing.Color = Color3.new(1, 0.12549, 0.12549)
		RightWing.CanCollide = false
		RightWing.Anchored = true
		RightWing.CFrame = part.CFrame * CFrame.new(((Amount/Stages) + 1)  * i,0,0)
		RightWing.TopSurface = Enum.SurfaceType.Smooth -- optional
		RightWing.BottomSurface = Enum.SurfaceType.Smooth -- optional

		local LeftWing = Instance.new("Part",workspace)
		LeftWing.Name = "Left Wing"
		LeftWing.Size = Vector3.new(1,1,1)
		LeftWing.Color = Color3.new(1, 0.12549, 0.1254)
		LeftWing.CanCollide = false
		LeftWing.Anchored = true
		LeftWing.CFrame = part.CFrame * CFrame.new(((Amount/-Stages) - 1) * i,0,0)
		LeftWing.TopSurface = Enum.SurfaceType.Smooth -- optional
		LeftWing.BottomSurface = Enum.SurfaceType.Smooth -- optional
	end

And you’re done! :smiley:

Full Code With No Commentary
local Amount = 0
local Stages = StageBetweenDistance
local Distance = PointsDistance

local Startpart = Instance.new("Part")
Startpart.Size = Vector3.new(1,1,1)
Startpart.CanCollide = false
Startpart.Anchored = true
Startpart.Position = START_LOCATION

local EndPart = Instance.new("Part")
EndPart.Size = Vector3.new(1,1,1)
EndPart.CanCollide = false
EndPart.Anchored = true
EndPart.CFrame = Startpart.CFrame * CFrame.new(0,0,-Distance)

for StageCount = 0, Stages do 
	local part = Instance.new("Part",workspace)
	part.Name = "Part"
	part.Size = Vector3.new(1,1,1)
	part.CanCollide = false
	part.Anchored = true
	part.CFrame = Startpart.CFrame * CFrame.new(0,0,((Startpart.Position - EndPart.Position).Magnitude/Stages) * StageCount)
	Amount = Amount + AmountPerStages
	for i = 1, Amount do 
		local RightWing = Instance.new("Part",workspace)
		RightWing.Name = "Right Wing"
		RightWing.Size = Vector3.new(1,1,1)
		RightWing.Color = Color3.new(1, 0.12549, 0.12549)
		RightWing.CanCollide = false
		RightWing.Anchored = true
		RightWing.CFrame = part.CFrame * CFrame.new(((Amount/Stages) + 1)  * i,0,0)
		RightWing.TopSurface = Enum.SurfaceType.Smooth -- optional
		RightWing.BottomSurface = Enum.SurfaceType.Smooth -- optional

		local LeftWing = Instance.new("Part",workspace)
		LeftWing.Name = "Left Wing"
		LeftWing.Size = Vector3.new(1,1,1)
		LeftWing.Color = Color3.new(1, 0.12549, 0.1254)
		LeftWing.CanCollide = false
		LeftWing.Anchored = true
		LeftWing.CFrame = part.CFrame * CFrame.new(((Amount/-Stages) - 1) * i,0,0)
		LeftWing.TopSurface = Enum.SurfaceType.Smooth -- optional
		LeftWing.BottomSurface = Enum.SurfaceType.Smooth -- optional
	end
end

NOTE : THIS METHOD WOULD CAUSE LAG FOR LOW-END COMPUTERS IF ABUSE TOO MUCH BUT SOME CHANGES COULD PREVENT LAGGING

This is my first Community Resource post, if you so happen to find a typo/error within my post, please tell me! :smile:

4 Likes