I don’t believe the 5 buttons I placed are properly in a circle kinda shape, so guessing there needs to be some sort of math code to get like half a circle or something to place them appropriately.
The main problem is the tweening. They ALL tween the right. They should tween like so
I got the file below with everything you need to test, etc.
local Frame = script.Parent
local Main = Frame:WaitForChild('Main')
local Opened = false
Main.Activated:Connect(function()
Opened = not Opened
if Opened then
for i = 1, 5 do
local Button = Frame:FindFirstChild('Button' .. i)
Button.Visible = true
Button:TweenPosition(UDim2.new(Button.Position.X.Scale + 0.05, 0, Button.Position.Y.Scale + 0.05, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.25, true)
wait(0.1)
end
else
for i = 1, 5 do
local Button = Frame:FindFirstChild('Button' .. i)
Button.Visible = false
Button:TweenPosition(UDim2.new(Button.Position.X.Scale - 0.05, 0, Button.Position.Y.Scale - 0.05, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.25, true)
wait(0.1)
end
end
end)
You will need to use Sin and Cos to accomplish this. This is some code I wrote to accomplish this.
for i, button in ipairs(self.buttons) do
--Use -90 to offset the initial position
local degree = -90 + ((i - 1) * 45)
local pos = UDim2.new(
.5 + 1.085 * math.cos(math.rad(degree)), 0,
.5 + 1.085 * math.sin(math.rad(degree)), 0
)
end
The 1.085 is the number I had to find to get the proper spacing between the center activator button and the surrounding radial buttons. Let me know if you have any questions.
Not sure if I’m missing something, but it didn’t alter the position of my buttons???
for i, button in ipairs(Buttons) do
--Use -90 to offset the initial position
local degree = -90 + ((i - 1) * 45)
local pos = UDim2.new(
.5 + 1.085 * math.cos(math.rad(degree)), 0,
.5 + 1.085 * math.sin(math.rad(degree)), 0
)
button.Position = pos
end
for i, button in ipairs(Frame:GetChildren()) do
if v:IsA('ImageButton') and button ~= MainButton then
--Use -90 to offset the initial position
local degree = -90 + ((i - 1) * 45)
local pos = UDim2.new(
.5 + 1.085 * math.cos(math.rad(degree)), 0,
.5 + 1.085 * math.sin(math.rad(degree)), 0
)
button.Position = pos
end
end
You also didn’t have
button.Position = pos
In the code you posted, but I’m assuming I’ve put it in the right spot?
Could it be that the buttons are being moved off-screen when the function is run?
Maybe you could try changing the two 1.085 values in the UDim2.new constructor to something much smaller, like 0.25.
Something I’d like to add: Please make your radial menu animate faster than that. Radial menus like that are supposed to be about making your UI get out of the way of gameplay. If you make it too slow to animate you’re defeating that very purpose of designing it as a radial menu in the first place.
for i, button in ipairs(Frame:GetChildren()) do
if button:IsA('ImageButton') and button ~= Main then
--Use -90 to offset the initial position
local degree = -90 + ((i - 1) * 45)
local pos = UDim2.new(
.5 + 0.5 * math.cos(math.rad(degree)), 0,
.5 + 0.5 * math.sin(math.rad(degree)), 0
)
button.Position = pos
end
end
for i, button in ipairs(Frame:GetChildren()) do
if button:IsA('ImageButton') and button ~= Main then
--Use -90 to offset the initial position
local degree = -90 + ((i - 1) * 45)
local pos = UDim2.new(
.5 + 1.085 * math.cos(math.rad(degree)), 0,
.5 + 1.085 * math.sin(math.rad(degree)), 0
)
button.Position = pos
end
end