I have been looking for a function to find all entities in a players view, but it doesn’t seem that one is implemented into the game. My question is, how would I go about writing one myself?
I have taken a look at Player:GetShootPos() and Player:GetAimVector(), but they would only provide everything directly under the player’s crosshair.
I thought of using ents.FindInCone(), but I’m not sure about how I’d go about using it with Player:GetAimVector().
Any ideas on doing this?
I tried the following, but got some weird results (seems to be 90 degrees offset?)
function GetEntsInView(ply) local eye_pos = ply:EyePos() local aim = ply:GetAimVector() local size = 35 return ents.FindInCone(eye_pos, aim, size, 0) end
I just made the ‘size’ value up, but in the end I guess it will use something such as the player’s FOV.