Line to check if the player is behind another player/NPC?

Title.

So, a tracer?

No, it’s more complicated than that

In truth, I was actually about to go about this myself today.
WorshipperQC’s knife SWEP from Mad Cow’s Weapons shows the basic gist of it:



/*---------------------------------------------------------
   Name: SWEP:EntityFaceBack
   Desc: Is the entity face back to the player?
---------------------------------------------------------*/
function SWEP:EntsInSphereBack(pos, range)

	local ents = ents.FindInSphere(pos, range)

	for k, v in pairs(ents) do
		if v ~= self and v ~= self.Owner and (v:IsNPC() or v:IsPlayer()) and IsValid(v) and self:EntityFaceBack(v) then
			return true
		end
	end

	return false
end


Uh, actually you gotta compare aim direction of both, player and entity in front of you and distance between you and the entity.

Huh?

So at the moment I’m actually working on a Riot Shield pointshop accessory that goes on your back. As such, I adapted Mad Cow’s formula to use on mine.



local angle = dmginfo:GetAttacker():GetAngles().y - player:GetAngles().y -- you'll need to substitute this with the players/NPCs you are trying to compare through some other function.
if RiotCheckAngleTrue(angle) then
BlehBlehBlehDostuff()
end
function RiotCheckAngleTrue(angle)
	if angle < -180 then angle = 360 + angle end
	if angle <= 50 and angle >= -50 then return true end

	return false	
end


Thanks!