[video=youtube;Zs7Kvy64N3k]http://www.youtube.com/watch?v=Zs7Kvy64N3k[/video]
I have performed the cardinal sin of [url=http://facepunch.com/showthread.php?t=1305151&p=42142198&viewfull=1#post42142198]using another person's code[/url] and integrating it into my script. Despite the horrendous judgement that may ensue from me asking for help with this code, I have absolutely no idea why this would fail. It seems like it renders just fine until I hit certain angles, and the code looks fine.
(note that I've enlarged the beam to a ridiculous extent for easy viewing - I'm not insane)
[code]if CLIENT then
hook.Add("PostPlayerDraw", "Laser.PostPlayerDraw", function( ply )
if !IsValid( ply ) then return end
local laserLine = Material( "models/kali/weapons/csgo/laser_beam_00_90.vmt" )
local laserDot = Material( "models/kali/weapons/csgo/weapon_red_dot_reflexsight.vmt" )
local weapon = ply:GetActiveWeapon()
if !IsValid( weapon ) or !weapon:IsWeapon( ) then return end
if weapon.HasAttachment[ "laserdot" ] then
local attID = weapon:LookupAttachment( "muzzle" )
if attID == 0 then attID = 1 end
local attPos = weapon:GetAttachment( attID ).Pos + Vector( 0, 0, -1.25 ) + ply:GetAimVector( ) * -.75
local wepTr = util.QuickTrace( attPos, ply:GetAimVector( ) * 40960, weapon )
cam.Start3D( EyePos( ), EyeAngles( ) )
render.SetMaterial( laserLine )
render.DrawBeam( wepTr.StartPos, wepTr.HitPos, 64, 0, 1, Color( 255, 255, 255, 255 ) )
render.SetMaterial( laserDot )
render.DrawQuadEasy( wepTr.HitPos, wepTr.HitNormal, 6, 6, Color(255, 0, 0, 255), 180 )
cam.End3D()
end
end )
end[/code]
I have switched out the sprites with the generic go-to laser sprite, and it causes no difference.
Also, off-topic and out of curiosity, would posting in this forum more often be considered annoying? I always Google before posting, and if I'm posting it's because I couldn't find anything. In my mind, (warranted) posting and getting a solution helps the community more than not. However, in my mind, that might appear to be more of a nuisance to many of the routine viewers of Developer Discussion.
PostPlayerDraw is only called after, as the name states, a player was drawn.
When you don't have a player entity in your field of view, it won't be drawn by the engine, and thus your hook won't get called, so your effect won't show up.
You'll have to use a different rendering hook, or consider using an effect/entity with it's [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index949a.html]renderbounds[/url] set to something large so it will render even when not in your field of view.
I'm assuming ply:SetRenderBoundsWS( wepTr.StartPos, wepTr.HitPos ) is a horrendous way to do it. It works, but is there a reason why I shouldn't do that?
Use [url=http://wiki.garrysmod.com/page/GM/PostDrawViewModel]PostDrawViewModel[/url] instead. It gives you the viewmodel, player, and weapon as arguments.
Sorry, you need to Log In to post a reply to this thread.