#How to check if player looks at an object
42 messages · Page 1 of 1 (latest)
In a local script you can use the player:getmouse() and you can use it to get the pos of the mouse In workspace I think
well it only gets mouse, i want actual player's view
Is the game first person?
no
ok so you want what the camera is looking at?
isnt that what i said?
well, by camera i thought the whole camera
like you know that shows everything around you
because camera can be faced to an object but player not
and i dont want that
ok
@digital merlin I made a script and it work but I didn't label what it does yet + it a short script
show it, i will try in thing i want to make
im labeling it
al
put in StarterCharacterScripts and in a LocalScript
local Player = game:GetService("Players")
local PlayerChar = script.Parent
local Camera = workspace.CurrentCamera
local CamPartHelp = Instance.new("Part")--[[I madee apart bc i cant get the Position of camera]]
CamPartHelp.Size = Vector3.new(0.1,0.1,0.1)--[[I size it bc why not]]
game:GetService("RunService").Stepped:Connect(function()
CamPartHelp.CFrame = Camera.CFrame
local Org = CamPartHelp.Position
local Dir = (PlayerChar:FindFirstChild("Head").Position - Org).Unit * 50 --<higher number make the range more far
local ray = Ray.new(Org,Dir)
local hit--[[what it hit]], pos--[[Position of the place it hit]] = workspace:findPartOnRay(ray--[[The raycast]],PlayerChar--[[Ignore the player character]])
if hit then
print("I see ".. hit.Name)
end
end)
do you understand the script?
well, what is camparthelp for?
i only make that part bc i dont think i can get position for the camera like i can only get the camera Cframe so i make the part get the camera cframe then turn the cframe into a position
** You are now Level 10! **
🥳
oh alr
works great just one problem, when i look straight, it detects baseplate is there a way to make it not happen?
idk I'm not too great at bug fixing as all my script usually work perfectly
alr
ima check if ik a way to fix it
i dont think you were looking straight bc when i look straight it didnt happened
Weird it didn't happen to me when I was testing
weird
make dir "Camera.CFrame.LookVector * 50" instead
also delete the camparthelp thing you do "Camera.CFrame.Position" to get the camera position
@digital merlin
coems 🤑
coems 🤑