Detecting if mouse is in a certain quarter of the screen

ive been trying to detect if the mouse is in a certain quarter of the screen.

here is a crappy rendition


id want to detect if the mouse is in a certain quarter in that circle. or well in a certain quarter of the screen.

or something like this

ive tried messing with mouseenter/mouseleave and ui corners but i just cant get the right shapes

Just curious, why do you want to do this?

Are those ‘quarters’ frames? If so, just use GetGuiObjectsAtPosition

Get the angle of the mouse relative to the center of the screen, then just check if the angle is within the interval that defines the boundary that you wish to detect it inside.

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local Client = Players.LocalPlayer

local Camera = Workspace.CurrentCamera
local Mouse = Client:GetMouse()
local Frame = script.Parent

local function MouseMoved()
	local X, Y = Mouse.X, Mouse.Y
	local W = Camera.ViewportSize / 2
	
	local Angle = math.atan2(Y - W.Y, X - W.X) -- angle will be between [-180, 180] such that quadrant 1 is defined as [-math.pi / 2, 0]
	
	if Angle < 0 and Angle > -math.pi / 2 then
		print("We are inside Quadrant 1!")
	end
	
	if Angle < 0 and Angle > -math.pi / 4 then
		print("We are in Octant 1!")
	elseif Angle < -math.pi / 4 and Angle > -math.pi / 2 then
		print("We are in Octant 2!")
	end
end

Mouse.Move:Connect(MouseMoved)
8 Likes

Thanks, i was thinking of something similar, just so happens I kinda didn’t get how to implement the math part of it. And for the middle I’m just gonna use the camera.viewportsize/2 to check distance from middle. On a side note I’m planning to use this for a combat system