Alright, so recently I've been messing around with the Camera. I want to find the 3D position the player is looking at using the camera. This is the code I'm using:
c = game.Workspace.CurrentCamera c.CameraSubject = game.Workspace.NewCam c.CameraType = "Attach" print(c:ScreenPointToRay(0,0))
After I press 'Play' in Studio, I check the coordinates that are printed into the output. This is what gets printed:
{-0.989541292, 30.9928341, 11.3838854}, {-0.759665072, 0.218074307, -0.612660289}
The coordinates are always a bit different. How do I use 'ScreenPointToRay' to find the 3D position the player is looking at?
The full script:
wait() plr = game.Players.LocalPlayer inputS = game:GetService("UserInputService") pressed = false mouse = plr:GetMouse() c = game.Workspace.CurrentCamera c.CameraSubject = game.Workspace.NewCam c.CameraType = "Custom" plr.CameraMaxZoomDistance = 0 print(c:ScreenPointToRay(0,0).Direction) -- ChatScript, CameraScript, ControlScript plr.PlayerScripts:WaitForChild("ChatScript") plr.PlayerScripts.ChatScript:Destroy() plr.PlayerScripts.ControlScript:Destroy() inputS.InputBegan:connect(function(i, gameProcessedEvent) if i.KeyCode == Enum.KeyCode.D then for i=1,15,1 do game.Workspace.NewCam.CFrame = game.Workspace.NewCam.CFrame + Vector3.new(1,0,0) wait(0.001) end elseif i.KeyCode == Enum.KeyCode.A then for i=1,15,1 do game.Workspace.NewCam.CFrame = game.Workspace.NewCam.CFrame + Vector3.new(-1,0,0) wait(0.001) end elseif i.KeyCode == Enum.KeyCode.W then --for i=1,15,1 do-- game.Workspace.NewCam.CFrame = mouse.Hit wait(0.001) --end elseif i.KeyCode == Enum.KeyCode.S then for i=1,15,1 do game.Workspace.NewCam.CFrame = game.Workspace.NewCam.CFrame + Vector3.new(0,-1,0) wait(0.001) end elseif i.KeyCode == Enum.KeyCode.G then print(c:ScreenPointToRay(0,0).Direction) end end) -- y + 15 in rotation
print(c:ScreenPointToRay(0,0).Direction)
Will display Vector3 that You are looking at Edit: Here is the workspace location point
print(c.CFrame * c:ScreenPointToRay(0,0).Direction)