Aligning half circle with Character

So I’ve been working on a circle positioning system and I’m having a bit of coders block

the goal is to center a half circle in front of the player

image

^ this is my issue

Code


local POINTS_TO_GEN = 10 -- points/parts to generate
local RADIUS = 7 -- size of the half circle
local CIRCLE = math.pi -- radius of a circle (half of a circle)

local Part = Instance.new("Part")
Part.Anchored = true
Part.Size = Vector3.new(1, 1, 1)

local Parts = {}
local Colors = {}

local module = {}

function module.DeletePoints() -- Cycles through generated points (parts) and deletes them
	for i = 1, #Parts do
		Parts[i]:Destroy()
	end
end

function module.GeneratePointColors() -- just vanity
	for i = 1, POINTS_TO_GEN do
		Colors[i] = BrickColor.Random()
	end
end

function XandZ(angle) 
	local x, z = math.cos(angle) * RADIUS, math.sin(angle) * RADIUS
	return x, z
end

function module.GeneratePoints(CCFrame) -- CCFrame is HumanoidRootPart CFrame
	if #Parts > 0 then module.DeletePoints() end
	
	for i = 1, POINTS_TO_GEN do
		
		local angle = i * (CIRCLE / POINTS_TO_GEN)
		local x, z = XandZ(angle)
		
		local NewPart = Part:Clone()
		
		NewPart.CFrame = (CCFrame * CFrame.new(x, 2, z)) -- point (part) positioning 
		
		NewPart.Parent = workspace
		NewPart.BrickColor = Colors[i]
		table.insert(Parts, NewPart)
	end
end

return module

I’ve googled and researched for a while but couldn’t find a way to position the half circle the way I want

any help is appreciated

local cf = torso.CFrame
local dir = cf.LookVector

for r = 0,1, 1/POINTS_TO_GEN do
    part.CFrame = cf * CFrame.Angles(0, math.rad(r*90 - 45), 0) * CFrame.new(0,0, -RADIUS) 
end

@Quoteory

My bad, was early in the morning typing on my phone.

For future reference, the atan2(x, z) takes the looking direction of an object and coverts it to a rotational value.
Useful for rotating guis.

1 Like

Isn’t working properly

I updated the code shortly after your response, did it work?

1 Like
function module.GeneratePoints(CCFrame) -- CCFrame is HumanoidRootPart CFrame
	if #Parts > 0 then module.DeletePoints() end
	
	for i = 0, POINTS_TO_GEN - 1 do
		
		local angle = i * (CIRCLE / (POINTS_TO_GEN - 1))
		
		local NewPart = Part:Clone()
		
		NewPart.CFrame = CCFrame*CFrame.Angles(0, angle, 0)*CFrame.new(RADIUS, 0, 0)
		
		NewPart.Parent = workspace
		NewPart.BrickColor = Colors[i+1]
		table.insert(Parts, NewPart)
	end
end
1 Like

Not sure I redid my code and swapped to manual positions because it worked better for what I needed

1 Like