Detect if position/entity is behind player


I need to know if a position/entity is behind a player but I can’t figure out how to do that, i need some help.


How far behind the player?

Create a vector between the object and the player, then find the angle between that vector and the player’s eye vector.

If the angle is between -90 and 90 degrees, the object is in front of the player, otherwise it’s behind them.

I tried this:

local ang = block[d]["pos"]:Angle().y - ply:EyePos():Angle().y
if(ang <= 90 && ang >= -90) then
    // Entity is in front of the player

But it’s not working and I tried with GetShootPos() too

local fwd = ply:EyeAngles():Forward()
local normal = (pos - ply:EyePos()):GetNormalized()
local isBehindPly = fwd:Dot(normal) < 0

where ply is the player and pos is the position.