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:
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
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
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)
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
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.