Raycasting with objects in a ViewportFrame?

Any ideas on how raycasting could be done in a manner to detect objects within a ViewportFrame? Obviously, simply trying to cast a ray won’t work, because raycasting only affects objects in the workspace. So the solution will have to be pretty clever. Has anyone tried to do this? Any ideas?

For context: I’m trying to detect when the mouse is over an object in a viewport frame, but I want it to be much more precise than simply detecting the mouse over the frame itself.

1 Like

There is a WorldModel object coming out that will have the functionality of the Workspace but viewport frames inherit from it, which means they get animation in raycasting. If you need the functionality now, I know Onogork has a solution you can check out: https://twitter.com/Onogork/status/1212072745263095816?s=20

5 Likes

Perhaps @Onogork could provide some insight? I remember he accomplished this before, but I don’t know his methods.

One possibility is to have clones in workspace that you raycast with and then make the results translate to the VPF models.

1 Like

Looks like his module is creating a clone of the viewport object and putting it into the actual workspace at the same position (but transparent/non-cancollide). It’s a pretty good workaround for this. I might use it for now.

@Nezuo I had never heard of the WorldModel object. Sounds really cool. That will be the ideal solution.

3 Likes

Would you direct us to somewhere we can read more about WorldModel? Perhaps a statement from Roblox somewhere?

Look at the last improvement on these release notes. Here is the API that @Maximum_ADHD showed on twitter. You can see it just moves workspace’s functionality into the WorldModel class. Workspace and ViewportFrames will inherit from this WorldModel.

2 Likes