render.DrawLine() - Positioning Help.

Hello Facepunch.

I’ve been having some difficulty with my entity i’ve been working on for the last 4 days now, I just can’t seem to position the ‘render.DrawLine()’ correctly. What I’m trying to do it position the line as if it’s like a lazer on a gun. I’m basically trying to position it straight to come outwards from the muzzle of the gun.

– Picture of turret.
http://prntscr.com/ce90tv

[LUA]
cam.Start3D2D(pos, ang, 0.7)

	render.DrawLine(self:GetGunBase():GetPos(),  self:GetGunBase():GetAngles():Forward() * 100, Color(255,0,0,255), true )
cam.End3D2D()

[/LUA]

– If someone can help me I’d really appreciate it, thank you.

-bump-

Use

Entity:LocalToWorld to easily tweak both positions as needed.

[editline]5th September 2016[/editline]

Why are you using Start3D2D? Don’t. Just put your rendering code in the Draw hook.

Ok, I’ll try that, thank you.

pretty sure you need to use cam.Start3D(), not Start3D2D

EDIT:



cam.Start3D();
render.DrawLine(self:GetGunBase():GetPos(), self:GetGunBase():GetPos() + self:GetGunBase():GetAngles():Forward() * 100, Color(255,0,0,255), true )
cam.End3D();


if you’re doing this in ENT:Draw you can remove the cam.Start3D/End3D

Thanks a bunch, it works!

[editline]5th September 2016[/editline]

Yeah, a silly mistake on my behalf, thanks.