Currently it is possible to raycast within ViewportFrames by using a WorldModel. I wanted to use this to be able to detect when parts in a ViewportFrame are clicked so I opted to use ScreenPointToRay on my ViewportFrame’s camera. The function doesn’t work as expected and produces a ray with the complete wrong direction.
System Information:
Intel (R) Core™ i7-6700K CPU @ 4.00GHz, 32 GB, NVIDIA GeForce RTX 2080 SUPER
Repro File:
ViewportFrame_ScreenPointToRay_Repro.rbxl (53.1 KB)
In the repro I’ve created a simple ViewportFrame with a camera pointing down at a baseplate. In play solo, clicking on the ViewportFrame will attempt to create a ball at the position where you click, and clicking outside of the ViewportFrame does the exact same thing but in the workspace. Observe how the ball appears in the workspace but never in the ViewportFrame, because ScreenPointToRay gives the wrong direction.
A user provided workaround to this problem here which I have tested and works but this is how the real functions should behave.
Note that this issue happens with both the ScreenPointToRay as well as the ViewportPointToRay functions
Expected behavior
If everything was working correctly, ScreenPointToRay and ViewportPointToRay would work in ViewportFrames exactly how they do on the workspace camera.