• Detect if position/entity is behind player
    5 replies, posted
Hello, 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. Thx
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: [code] local ang = block[d]["pos"]:Angle().y - ply:EyePos():Angle().y if(ang <= 90 && ang >= -90) then // Entity is in front of the player end [/code] But it's not working and I tried with GetShootPos() too
[code] local fwd = ply:EyeAngles():Forward() local normal = (pos - ply:EyePos()):GetNormalized() local isBehindPly = fwd:Dot(normal) < 0 [/code] where ply is the player and pos is the position.
[QUOTE=Wyozi;47786044][code] local fwd = ply:EyeAngles():Forward() local normal = (pos - ply:EyePos()):GetNormalized() local isBehindPly = fwd:Dot(normal) < 0 [/code] It work, thx :) ! where ply is the player and pos is the position.[/QUOTE]
Sorry, you need to Log In to post a reply to this thread.