I plan on creating a method that will detect when certain objects are within your sight (On your screen, so to speak.). It is important to note that my game will be in a permanent First Person View state, so I have created a Ray, who's origin is the characters head, and the direction is the heads lookVector. Anyway, using that Ray it was easy for me to detect what object I am staring at right INFRONT of me, but it will not detect the objects in the places my mouse is not pointing at. Do you understand? What I want is that somehow, with Rays or without, i'll be able to detect whether or not a certain object is within the players sight. Thank's in advance!
local listOfItems = {workspace.Object1, workspace.Object2} repeat wait() until game.Players.LocalPlayer.Character local head = game.Players.LocalPlayer.Character.Head local AngleOfSight = 15 --Everything within 15 degrees will be seen function inSight(hitPos, headPos) local scan = head.CFrame.lookVector local vect = hitPos-headPos return math.acos((vect.X*scan.X+vect.Y*scan.Y+vect.Z*scan.Z)/vect.magnitude)<AngleOfSight end while wait() do local itemsInSight = {} local startPos = head.Position for i, v in pairs(listOfItems) do local ray = Ray.new(head.Position, (v.Position-head.Position).unit*999) local cast, hit = workspace:FindPartOnRay(ray, head.Parent) if cast and cast == v and inSight(hit, startPos) then table.insert(itemsInSight, v) end end end