Drawing lines from players eye position?

This was originally posted in “Problems that don’t need their own thread”, but after multiple replies people lost interest and I felt like it was getting a bit spammy so it was moved here.

I am trying to draw a line from every player’s eye position to where they are looking, and I have tried multiple ways to do this but none of them seem to work.

Here is the code that I am currently working with:



function DrawEyeLines()
	for k, v in pairs( player.GetAll() ) do
		if not tobool(DrawEyeTraces:GetInt()) then return end -- Enable/disable
		local vm = v:EyePos()
		local t = util.GetPlayerTrace(v)
		local tr = util.TraceLine(t)
		render.SetMaterial(Material("cable/new_cable_lit"))
		render.DrawBeam(EyePos(), tr.HitPos, 5, 0, 12.5, Color(255, 0, 0, 255)) --2
		local Size = 3
		render.SetMaterial(Material("Sprites/light_glow02_add_noz")) -- Draw a laser dot where the line hits something.
		render.DrawQuadEasy(tr.HitPos, (EyePos() - tr.HitPos):GetNormal(), Size, Size, Color(255,0,0,255), 0)
	end
end
hook.Add("PostDrawTranslucentRenderables", "THISISUNIQUE", DrawEyeLines)


This code doesn’t seem to do anything, and it doesn’t produce any errors.

I cant see what is wrong, can anyone help?

Thank you.


local vm = v:EyePos()

You defined this variable but you never used it. The beams are drawn from the Client’s eyeposition to the player’s hit position. Perhaps change your drawbeam start positions to it?




render.DrawBeam(EyePos(), tr.HitPos, 5, 0, 12.5, Color(255, 0, 0, 255)) --2 
local Size = 3 render.SetMaterial(Material("Sprites/light_glow02_add_noz")) -- Draw a laser dot where the line hits something.
 render.DrawQuadEasy(tr.HitPos, (EyePos() - tr.HitPos):GetNormal(), Size, Size, Color(255,0,0,255), 0)

Here you use the client’s EyePos(). Replace that with vm and see what happens

Damn, I am stupid.
Thank you very much! =)