Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by
cabbler 1942 Moderation Voter
6 years ago

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)
0
C: Thanks , i finally can make a radial menu. Rodrigo2003 76 — 6y
Ad

Answer this question