[Help wanted :)] How would I code a beam Cone AOE visable? (I have the code for the actual cone AOE) - Anime Odyssey Defense

Hi I am currently making a tower defense game with a cone AOE visual!

I have a beam made up of 3 parts for a visual of the cone AOE but I would like to know to put the placements for the 3 parts I know the 2nd part i just going to be the humanoid root part. I need to have it fit the magnitude too.

Like this as a example:

local function IsInFov(Anchor, Target, Fov)
	if not (typeof(Target) == "Vector3") then
		if not Target:IsA("BasePart") then return end
		Target = Target.Position
	end
	if not (typeof(Anchor) == "CFrame") then
		if not Anchor:IsA("BasePart") then return end
		Anchor = Anchor.CFrame
	end
	local A = (Anchor.Position - Target).Unit
	local B = -Anchor.LookVector
	local dp = A:Dot(B)
	return(dp > math.clamp(90-Fov, 1, 90)/90)
end

local function ToDamageCone()
	local Range = script.Parent.Settings.Range.Value
	local Best = nil
	local BestDistance = nil


	local Choosing = nil
	for i,v in pairs(game.Workspace.Mobs:GetChildren()) do
		local Distance = (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
		local Distance2 = (v.HumanoidRootPart.Position - game.Workspace.Naruto.Waypoints[v.MovingTo.Value].Position).Magnitude
		if Distance < Range then
			IsInFov(script.Parent.PrimaryPart, v.HumanoidRootPart, script.Parent.Settings.Type.Wide.Value)
		end
	end

	local tc = CFrame.lookAt(script.Parent.HumanoidRootPart.Position, Choosing.HumanoidRootPart.Position)

	gyro.CFrame = tc
	
	
	
end

I hope there is a simple soution but if you guys need the code above for your cone AOE go ahead :slight_smile:

pls help cus like no one help me I will even give you me robux

I just want the idea for how to do it like I can script it myself if I have a idea on how to do it

I have figured it out and for any other tower defense scripters here is my code:

local function Go(Cframe)
-- PHT is the place holder tower and if you are doing this when the script is inside a character than replace this with script.Parent

	if PHT then
	if PHT.Settings.Type.Value == "Cone" then
		if Part1 and Part2 and Part3 then
			Part1.Parent = PHT
			Part1.CFrame = CFrame.new(Cframe)
			Part1.Anchored = true
			Part1.Transparency = 1
			Part1.CanCollide = false

			Part2.Parent = PHT
			Part2.CFrame =CFrame.new(Part1.CFrame.Position)
			warn(Part2.CFrame)
			warn("IDK")
			warn(Part1.CFrame)
			local Value = math.floor(Part1.Orientation.Y + (((PHT.Settings.Type.Wide.Value/2))))
			warn(Value)
			Part2.CFrame = CFrame.Angles(math.rad(0), math.rad(Value), math.rad(0))
			warn(CFrame.Angles(math.rad(0), math.rad(Value), math.rad(0)))
			Part2.Anchored = true
			Part2.Transparency = 1
			Part2.CanCollide = false
			warn(Part2.CFrame + (Part2.CFrame.LookVector * PHT.Settings.Range.Value))

			Part2.Beam.Attachment0 = Part2.Attachment
			Part2.Beam.Attachment1 = Part1.Attachment

			warn(Part1.CFrame)
			Part3.Parent = PHT
			Part3.CFrame = CFrame.new(Part1.CFrame.Position)
			local Value2 = math.floor(Part1.Orientation.Y + (((PHT.Settings.Type.Wide.Value/2) * -1)))
			warn(Value2)
			Part3.CFrame = CFrame.new(Part1.CFrame.Position)
			warn(Part3.CFrame)
			warn("IDK")
			Part3.CFrame = CFrame.Angles(math.rad(0), math.rad(Value2), math.rad(0))
			warn(CFrame.Angles(math.rad(0), math.rad(Value2), math.rad(0)))
			Part3.Anchored = true
			Part3.Transparency = 1
			Part3.CanCollide = false
			--workspace.Part.CFrame = workspace.Part.CFrame + workspace.Part.CFrame.LookVector * 2
			warn(Part3.CFrame + (Part3.CFrame.LookVector * PHT.Settings.Range.Value))
			--Part3.CFrame = Part3.CFrame + (Part3.CFrame.LookVector * script.Parent.RNG.Value)
			warn(Part3.CFrame.LookVector)


			warn("if this doesn't work than idk")
			warn(Part1.CFrame + (Part3.CFrame.LookVector * PHT.Settings.Range.Value))
			warn(Part1.CFrame + (Part2.CFrame.LookVector * PHT.Settings.Range.Value))

			Part3.CFrame = Part1.CFrame + (Part3.CFrame.LookVector * PHT.Settings.Range.Value)
			Part2.CFrame = Part1.CFrame + (Part2.CFrame.LookVector * PHT.Settings.Range.Value)

			warn(Part3.CFrame)
			Part3.Beam.Attachment0 = Part3.Attachment
			Part3.Beam.Attachment1 = Part1.Attachment
			warn("Done")
			Part3.Anchored=true 
			Part2.Anchored=true 
			Part1.Anchored=true 
		else
				Part1 = game.ReplicatedStorage.Cone:Clone()
				Part1.Parent = PHT
				Part1.CFrame = CFrame.new(Cframe)
				Part1.Anchored = true
				Part1.Transparency = 1
				Part1.CanCollide = false
				Part1.Beam:Destroy()

				Part2 = game.ReplicatedStorage.Cone:Clone()
				Part2.Parent = PHT
				Part2.CFrame =CFrame.new(Part1.CFrame.Position)
				warn(Part2.CFrame)
				warn("IDK")
				warn(Part1.CFrame)
				local Value = math.floor(Part1.Orientation.Y + (((PHT.Settings.Type.Wide.Value/2))))
				warn(Value)
				Part2.CFrame = CFrame.Angles(math.rad(0), math.rad(Value), math.rad(0))
				warn(CFrame.Angles(math.rad(0), math.rad(Value), math.rad(0)))
				Part2.Anchored = true
				Part2.Transparency = 1
				Part2.CanCollide = false
				warn(Part2.CFrame + (Part2.CFrame.LookVector * PHT.Settings.Range.Value))

				Part2.Beam.Attachment0 = Part2.Attachment
				Part2.Beam.Attachment1 = Part1.Attachment

				Part3 = game.ReplicatedStorage.Cone:Clone()
				warn(Part1.CFrame)
				Part3.Parent = PHT
				Part3.CFrame = CFrame.new(Part1.CFrame.Position)
				local Value2 = math.floor(Part1.Orientation.Y + (((PHT.Settings.Type.Wide.Value/2) * -1)))
				warn(Value2)
				Part3.CFrame = CFrame.new(Part1.CFrame.Position)
				warn(Part3.CFrame)
				warn("IDK")
				Part3.CFrame = CFrame.Angles(math.rad(0), math.rad(Value2), math.rad(0))
				warn(CFrame.Angles(math.rad(0), math.rad(Value2), math.rad(0)))
				Part3.Anchored = true
				Part3.Transparency = 1
				Part3.CanCollide = false
				--workspace.Part.CFrame = workspace.Part.CFrame + workspace.Part.CFrame.LookVector * 2
				warn(Part3.CFrame + (Part3.CFrame.LookVector * PHT.Settings.Range.Value))
				--Part3.CFrame = Part3.CFrame + (Part3.CFrame.LookVector * script.Parent.RNG.Value)
				warn(Part3.CFrame.LookVector)


				warn("if this doesn't work than idk")
				warn(Part1.CFrame + (Part3.CFrame.LookVector * PHT.Settings.Range.Value))
				warn(Part1.CFrame + (Part2.CFrame.LookVector * PHT.Settings.Range.Value))

				Part3.CFrame = Part1.CFrame + (Part3.CFrame.LookVector * PHT.Settings.Range.Value)
				Part2.CFrame = Part1.CFrame + (Part2.CFrame.LookVector * PHT.Settings.Range.Value)

				warn(Part3.CFrame)
				Part3.Beam.Attachment0 = Part3.Attachment
				Part3.Beam.Attachment1 = Part1.Attachment
				warn("Done")
				Part3.Anchored=true 
				Part2.Anchored=true 
				Part1.Anchored=true 
				Part3.Beam.Enabled = true
				Part2.Beam.Enabled = true
				Part1.Beam.Enabled = true
				Part1.Attachment.CFrame = CFrame.new(0,0,0)
				Part2.Attachment.CFrame = CFrame.new(0,0,0)
				Part3.Attachment.CFrame = CFrame.new(0,0,0)
		end	
	end
	end
end

image
Cone part will be in replicated storage and have the beam turned off at first so when you do it on a server script than it won’t show all the time and you can make it to where it will be enabled when you are currently upgrading the unit :slight_smile: .
image
All done

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.