Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how can I make my ray point towards the mouse position and not the cameras lookvector?

Asked by 4 years ago

im looking for a substitute for mouse.hit but this does not make a ray pointing to the mouse position like the wiki said it would, please help

local uIS = game:GetService("UserInputService")
local mouse = uIS:GetMouseLocation()
local camera = workspace.CurrentCamera
uIS.InputBegan:Connect(function(input, processed)
    if processed then return end
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        local unitRay = camera:ViewportPointToRay(mouse.X, mouse.Y, 0)
        local ray = workspace:Raycast(unitRay.Origin, unitRay.Direction * 100)
        if ray then
            print(1)
            print(ray.Instance.Name)
        end
    end
end)

Answer this question