Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get the mouse angle based on the "center" value ?

I made a script that can give me the angle of the mouse arround the Center Value

--[[
		 90
		  |
 380 -- Center -- 180
		  |
	     270
--]]

But i dont know how i can get the Scale of the Center Position it is only getting the Offset of the Position.


Center = Vector2.new(UDim2.new(0.5,0,0.5,0)) -- idk what i am doing anymore

-- calculation to obtain the angle that is just getting the offset

Angle = (math.atan2(MousePos.y-Center.X, MousePos.x-Center.Y)*180 / math.pi)+180;

1 answer

✓ Accepted answer

UDim2 is merely a way to tell guis to reach a proper size. It does nothing here.

I recommend using half of the screen size, which you can get in cameras.

To get the proper angle you should subtract identical axises; ur very close. Also there is a builtin degrees function use that.

Lastly I don't recommend pascaling every variable like that but w/e. enjoy!!

local mouse = game.Players.LocalPlayer:GetMouse()

local center = workspace.CurrentCamera.ViewportSize/2
local angle = math.deg( math.atan2(mouse.Y-center.y, mouse.X-center.x) ) + 180
print(angle)

1 comment

0

C: Thanks , i finally can make a radial menu.

This discussion is preserved as it was. New answers, comments, and votes are closed.