How do I get whats in sight of the entity?

Full edit:

The DrawBeam works just as supposed, but the tracedata with same position doesn’t work.
I want the trace to check for anything non world passes through the beam.



function ENT:Draw()
--explodeTime = self:GetNWInt("explodeTime")
	self:DrawModel()
	self:SetColor(Color(255, 255, 255, 255))

	local Pos = self:GetPos()
	local Ang = self:GetAngles()
	surface.SetFont("HUDNumber5")
	local PosTwo = Vector(Pos.x, Pos.y, Pos.z)
	local tracedata = {}
	tracedata.start = self:LocalToWorld( Vector( 0, -2.5, 58.5 ) )
	tracedata.endpos = self:LocalToWorld( Vector( 450, -2.5, 58.5 ) )
 
	local trace = util.TraceLine(tracedata)
	if trace.HitNonWorld then
          -- there's code here
	end
        local Vector1 = self:LocalToWorld( Vector( 0, -2.5, 58.5 ) )
	local Vector2 = self:LocalToWorld( Vector( 450, -2.5, 58.5 ) )
 
	render.SetMaterial( Laser )
	render.DrawBeam( Vector1, Vector2, 4, 1, 1, Color( 0, 63, 255, 255 ) ) 
	
	Ang:RotateAroundAxis(Ang:Up(), -90)
	Ang:RotateAroundAxis(Ang:Forward(), 7)
	local TextWidth = surface.GetTextSize(x)
	cam.Start3D2D(Pos + Ang:Up() * 55.5, Ang, 0.1)		
	draw.WordBox(-2.5, -TextWidth*-1.13, 0, x, "HUDNumber5", Color(140, 0, 0, 140), Color(255,255,255,255))
	cam.End3D2D()
end


Changed!

Bump.

“it doesn’t work” is extremely vague, more details please.

I suspect the trace just gets stuck inside the entity it’s coming from (aka self), you might want to filter it out by doing “tracedata.filter = self”.

Works great! Thank you!