ViewportFrame:ViewportPointToRay

As a Roblox developer, it is currently too hard to raycast accurately within ViewportFrames.

I have a building game where players can place blocks, and a UI to paint different parts of them before placing. Instead of having 2D buttons for each part, I wanted to allow them to click directly on the parts inside the ViewportFrame as if they were the buttons.

I assumed that I could use ViewportPointToRay on the ViewportFrame’s CurrentCamera to detect when parts are clicked, but as staff explained here, not all cameras necessarily have a unique ViewportSize, so it assumes the size is (1,1) causing ViewportPointToRay to give incorrect results.

If Roblox is able to address this issue, it would improve my development experience because I could create interactable 3D UI without manually converting a screen point to a world position. I think that since this functionality already exists for the workspace camera, it would be intuitive to have an equivalent method for ViewportFrames.

5 Likes