how to cast a ray that points towards the mouse location and originates from the camera position?
I need this done using user input service, the wiki claims that it is more powerful but lacks built in mouse functions. for anyone confused I basically need mouse.Hit but using user input service. I have tried using camera:ViewPortPointToRay(X, Y, 1) but that doesn't seem to make a ray that points towards the mouses location in 3d space but instead the look vector of the cameras cframe. I want the mouses position in 3d space, not the cameras look vector. passing the mouses x and y into viewport doesn't seem to make a ray pointing to the vector 3 equivilent.
01 | UIS.InputBegan:Connect( function (input,processed) |
02 | if processed then return end |
03 | if input.KeyCode = = Enum.KeyCode.E then |
04 | local mouseLocation = UIS:GetMouseLocation() |
05 | local unitRay = camera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y * 0 ) |
06 | print ( "Camera positioin: " .. tostring (camera.CFrame.Position)) |
07 | print ( "Unit ray position: " .. tostring (unitRay.Direction)) |
08 | local p = Instance.new( "Part" , workspace) |
09 | p.Size = Vector 3. new( 1 , 1 , 1 ) |
11 | p.BrickColor = BrickColor.Blue() |
12 | p.CFrame = CFrame.new(unitRay.Origin, unitRay.Direction) |