I can't figure out math for a semi-simple radial menu

I’ll keep it short, so you know radial menus right? They’re pretty cool, for the most part they also seem simple, except for one thing about them.

A few good radial menus have these lines in the middle that divide the circle into segments, whether it be 2 items in the menu or 3 or 4, they always seem to perfectly divide the circle depending on the amount of items inside it. I want to know how to do that and I’ve genuinely tried but it always leads back to square one with me scratching my head on how I’m supposed to do the math to position and rotate it all correctly.

This is all being done using GUI Objects, no parts or anything like that.

I think I’m going completely in the wrong direction with all of this however, so I need some help on what I should be doing when it comes to the mathematical stuff.

Here’s an image on what I’m hoping to create, but more white lines get created as more objects get added to the menu.

this might help… i dont know how to apply it or where to use it but you can try something with it. i use it to multiply cframes.

(do this for each section)

local radius = 3
local angle = SECTION_NUMBER * (math.pi*2 / #TOTAL_SECTIONS)
local x = math.cos(angle) * radius
local z= math.sin(angle) * radius
1 Like

Ah, that seems sort of similar to what I’m trying currently.

local RADIUS = .35
local NUM_OPTIONS = 3
local ANGLE_OFFSET = 90
local menuItems = {}

-- Create a screen and frame for the menu
local menuScreen = script.Parent
menuScreen.Name = "MenuScreen"
local menuFrame = menuScreen.Main

-- Define position and size for the menu frame in both opened and closed states
local menuOpenPosition = UDim2.new(0.283, 0,0.026, 0)
local menuOpenSize = UDim2.new(0.565, 0,0.947, 0)
local menuClosedPosition = UDim2.new(.5, 0, .5, 0)
local menuClosedSize = UDim2.new(0.005, 0, 0.005, 0)

-- Define the element for the menu options
local itemTemplate = script.h

local function newMenuItem(name, angle, range)
	local newItem = {}
	local label = itemTemplate:Clone()
	local line = script.e:Clone()
	label.Parent = menuFrame.ImageLabel
	line.Parent = menuFrame
	local angleRadians = math.rad(ANGLE_OFFSET + angle)
	line.Rotation = #menuItems * (math.pi*2 / #NUM_OPTIONS)
	label.Position = UDim2.new(0.5 + RADIUS * math.cos(angleRadians) - label.Size.X.Scale / 2, 0, 0.5 - RADIUS * math.sin(angleRadians) - label.Size.Y.Scale / 2, 0)
	table.insert(menuItems, newItem)

for i = 1, NUM_OPTIONS do
	local angle = (360 / NUM_OPTIONS) * (i - 1)
	local name = "Option" .. i
	newMenuItem(name, angle, 360 / NUM_OPTIONS)

As you can see, when it comes to the line part, I’m sort of really screwing it up, the part where I can put the object in is perfectly fine, it’s just the line that I’m failing to comprehend.

The way that I’m doing it is that I’m using a custom image that’s the same size as the circle, it’s merely just a line that starts at the center and ends at the very right of the image, essentially covering one half of the circle.

1 Like

here is a demo project
RadialMenu.rbxl (37.7 KB)

and this is the script

local amount = 3
local angle = math.pi * 2 / amount
local angleOffset = math.rad(90)
local line = script.Parent.Line
line.Parent = nil

for i = 1, amount do
	local lineAngle = i * angle + angleOffset
	local clone = line:Clone()
	clone.Position = UDim2.new(0.5 + math.cos(lineAngle) / 4, 0, 0.5 + math.sin(lineAngle) / 4, 0)
	clone.Rotation = math.deg(lineAngle)
	clone.Parent = script.Parent

It took a while to adapt the code to my project but holy heck it works almost flawlessly, thank you!

1 Like