I’m aware that this topic has been mentioned a few times on the forums. However, most of these topics pre-date the addition of WorldModels for viewport frames.
How could I implement the raycasting offered by WorldModel to achieve the functionality of Mouse.Hit in a ViewportFrame? Documentation and related issues are rather vague in their description of this topic.
Edit: I should probably add, I specifically need to know how to get the mouse’s world position inside the viewport, based on where the mouse is in the viewport.
You should be able to use the Camera:ViewportPointToRay() function in order to cast a ray from a point on the ViewportFrame. Assuming of course that you do have a camera inside the frame.
Call on CurrentCamera of Viewport method ScreenPointToRay, and use direction to fire Raycast from WorldModel of ViewportFrame. In theory this should work.
Could you provide an example? I’ve tinkered with this solution for days now and have been unable to create a result that functions as expected.
My viewport frame has a camera looking downwards on a static plane upon a “map”. Simply supplying the mouse position (with absolute position accounted for) does not result in the ray hitting the expected location below. The farther away from the origin of the camera, the more inaccurate it is, ranging anywhere from a few studs away from the mouse location to hundreds of studs away, depending on the camera’s height from the map.