How to calculate offset based on device size?

I am detecting the position of the mouse and whether it is near the side of the screen. I need to somehow calculate the offset that is “on the side” by using the screen size to determine that position. How would I do this?

local mousevariable = player:GetMouse() returns the mouse object

from there you can call:

local ScreenSizeX = mousevariable.ViewSizeX
local ScreenSizeY = mousevariable.ViewSizeY

local Corner = Udim2.fromOffset(ScreenSizeX, ScreenSizeY)

and then subtract the current mouse position from that “Corner” value

1 Like

You would retrieve the value of the viewport size. To get it, use Camera.ViewportSize.

I would recommend it over the Mouse.ViewSize[X/Y] because this returns a Vector2 object.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.