Mapping mouse position to World Model Position

Hey, so basically I got three viewport frames here like so:

I’m trying to see if the player’s mouse is hovering over any of the dummies in the viewport frames. Here’s a quick tree to show you what I’m working with:
Screenshot 2025-04-19 at 10.31.57 PM

I’ve been trying to use Camera:ViewportPointToRay() and then raycasting, but the result keeps returning nil. Any idea how to implement this?

The current code I’m trying:

for _, frame in self.player.PlayerGui.CharacterSelection.main:GetChildren() do
		if frame:IsA("Frame") then
			local viewport = frame:FindFirstChildWhichIsA("ViewportFrame")
			if not viewport then return end

			local world = viewport:FindFirstChildWhichIsA("WorldModel")
			
			local cam = Instance.new("Camera", viewport)
			cam.CFrame = CFrame.new(0, 20, 19) * CFrame.Angles(0, 0, 0)
			
			viewport.CurrentCamera = cam
			local connection
			
			viewport.MouseEnter:Connect(function()
				connection = UIS.InputChanged:Connect(function(input, processed)
					if input.UserInputType == Enum.UserInputType.MouseMovement then
						local ray = cam:ScreenPointToRay(input.Position.X, input.Position.Y)
						
						local hit = world:Raycast(ray.Origin, ray.Direction * 100)
						print(hit)
					end
				end)
			end)
			
			viewport.MouseLeave:Connect(function()
				connection:Disconnect()
			end)
		end
	end
1 Like

Mouse enter is an event that checks if mouse entered gui so do what you wanna do after the event is fired

1 Like

After that’s fired, I need to see if the mouse is hovering over the dummy inside the viewport

Not really sure if its possible to check if the mouse hovers on the dummy try making a gui its size is exactly the size of the dummy and check if the mouse hovers on it

This is definitely going to be the last resort in case there isn’t any solutions to this

I found someone on twitter who created a viewportframe that supports raycasting i think thats what you are looking for
https://x.com/Onogork/status/1212072745263095816?s=20
Edit:nvm the module isnt accessible

Yeah no, I can raycast inside the WorldModel. The issue is converting the 2d screen position of the mouse into the 3d position of the WorldModel (not Workspace)

Good luck with finding a solution thats the best i can do

WorldModel was made to fix all these issues lol. Its only getting the position of the mouse in the WorldModel that I can’t figure out.

Thanks for trying to help, I appreciate it

1 Like

I found a solution you can create frames on every part of the Dummy then make a script to see if mouse is hovered on any of these frames use CollectionService to put it all in one script

1 Like

Yeah I can definitely do this, but like I said I would prefer a more intuitive solution as the models are just placeholders and the actual models will be much more detailed.

Bumping, sorry if I sound impatient, I just want to get this done as quick as possible