GuiObject position transform function

As a developer, it can be annoying to find the position of the mouse relative to a ui element (and vice versa). This is useful for running drag and hover effects, and it can be very complex to implement when you’re working with something like a BillboardGui or a SurfaceGui.

Vector2 GuiObject:ViewportPositionToObject(position: Vector2)
Vector2 GuiObject:ObjectToViewportPosition(position: Vector2)
1 Like

Thank you for this I don’t even know how can I use it because I don’t work on GUI but it looks really helpful maybe I can use it in the future👩‍🔧

1 Like

I think you’re looking for the following functions that are within the Camera object.

ViewPointToRay
This creates a ray that can be used in the Workspace:RayCast() that can then be used to detect where in 3D space has been hit.

and

WorldToScreenPoint
Takes a Vector3 point and returns a Vector2 point of where that Vector3 would appear on screen.

1 Like

Those are different from what OP’s looking for. The methods in the Camera object deal with transforming points to and from the viewport (3D view) onto the screen (2D view) as well as constructing rays for raycasting. OP wants a 2D transform for relative position checking (like CFrame Object/World space but for 2D UI).

1 Like