Now, I want to recreate it for my mini project and I don’t know where to start. I have already made a simple gui but I was wondering how to make it responsive to mouse movements.
e.g
-Moving the mouse upwards will highlight/preview the weapon that is located above the wheel.
-Same goes to moving on different directions, different weapons on the wheel will be highlighted according to where the player moves the mouse.
Feel free to drop other links of topics that has already achieved this. However, I would appreciate it if you are able to give me suggestions on what to use in the Roblox API Reference with the link attatched to it as I think it is the best way for me to enhance my knowledge. If you have any questions/confusions please ping me in the comments/replies, I am currently new to devforums so I don’t know much about how things work.
no api references just math
first start by getting relative position of the mouse to center of the screen
-- in pixels i.e. Vector2
local Camera = workspace.CurrentCamera
local Center = Camera.ViewportSize / 2
-- get mouse position using UserInputService:GetMouseLocation() - Vector2.new(0, TopbarSizeY)
-- no need to subtract topbar size Y if screengui ignoreGuiInset is set to true
local RelativePosition = MousePosition - Center
relative mouse position to center means starting point of mouse position would be screen centre
lets normalise this vector as we only need the direction
local Direction = RelativePosition.Unit
now we can find dot product of the mouse direction and for example positive X axis i.e. Vector2.new(1, 0)
local XAxis = Vector2.new(1, 0)
local dotProduct = Direction:Dot(XAxis)
since both vectors are unit vectors our dot product value is cosine of the angle
local Angle = math.acos(dotProduct)
-- Angle is in radians
-- convert to degrees if you would like to display current angle
print(math.deg(Angle))
-- equivalent to Angle * 180/pi
using this angle check whether the mouse is within given range to point out which ui is selected