Render.DrawBeam square off a wall?

How would I draw a laser beam square of the wall instead of this mess?

Well for a start you post your code.

Second of all, it looks like you are using the angles of the entities to trace the beam. When placing them (presumably with an attack trace), use the ‘Normal’ angles from the trace. This will give you the angles that is a right angle to the wall.

Sorry I thought i did.

[lua]
local Laser = Material( “cable/redlaser” )

function ENT:Draw()
 
	self:DrawModel() 
 
	local Vector = self:LocalToWorld( Vector( 0, 0, 200 ) )

	render.SetMaterial( Laser )
 	render.DrawBeam( self:GetPos(), Vector, 12, 1, 1, Color( 255, 255, 255, 255 ) ) 

end 

[/lua]

Try this instead:

[lua]
local Laser = Material( “cable/redlaser” )

function ENT:Draw()
 
	self:DrawModel() 
 
	local Vector = self:GetPos() + self:GetUp()*1000

	render.SetMaterial( Laser )
 	render.DrawBeam( self:GetPos(), Vector, 12, 1, 1, Color( 255, 255, 255, 255 ) ) 

end 

[/lua]

Obviously, using traces instead of just 2 vectors like this would be better (as long as you don’t do it each time in a draw hook).

Something else to note, your storing it in “Vector” which is also the function name of creating vectors which will make your code error if you use Vector( some, args, here ) later on in that draw function due to you overwriting the Vector function.

I’d recommend you change the “local Vector” to “local vector” to avoid future issues.

Hadn’t picked up on that.

Sorry I stripped the function down to simplify things before posting. I noticed it when I tested out Dingusnin’s fix which did not seem to behave any different then my code.

I didn’t know ent:GetUp((), GetForward(), GetRight() existed. If I was to use one of these would I just make sure the bottom of the grenade was stuck to the wall? Or is there a better approach?

Well one week later and countless hours I finally got it working! Such a happy moment in my life! There is one problem through, it only works maybe 75% of the time. I’m sure this is a terrible way to do this, but here is a screenshot of the problem and the code:

Be prepared to laugh



function ENT:SetLaserDirection(data, phys)

	local collisionPos = data.HitPos
	local entPos = self:LocalToWorld(self:OBBCenter())
									
	local vectorX_difference = collisionPos.x - entPos.x
	local vectorY_difference = collisionPos.y - entPos.y
	local vectorZ_difference = collisionPos.z - entPos.z
											
		if vectorX_difference > 2  then
			self:SetNetworkedVector("laserVector", Vector(-1000, 0, 0))
		elseif vectorX_difference < -2 then
			self:SetNetworkedVector("laserVector", Vector(1000, 0, 0))
		end
		
		if vectorY_difference > 2  then
			self:SetNetworkedVector("laserVector", Vector(0, -1000, 0))
		elseif vectorY_difference < -2 then
			self:SetNetworkedVector("laserVector", Vector(0, 1000, 0))
		end
		
		if vectorZ_difference > 2  then
			self:SetNetworkedVector("laserVector", Vector(0, 0, -1000))
		elseif vectorZ_difference < -2 then
			self:SetNetworkedVector("laserVector", Vector(0, 0, 1000))
		end
					
end



function ENT:Draw()
	
     self:DrawModel() 
		
	local entPos = self:GetPos()
		
	if self:GetNetworkedBool("DrawLaser") then
		render.SetMaterial( Laser )
		self:SetRenderBoundsWS( entPos, self:GetNetworkedVector("laserVector") - entPos )
		render.DrawBeam( entPos, entPos + self:GetNetworkedVector("laserVector"), 12, 1, 1, Color( 255, 255, 255, 255 ) ) 
	end
end