• Disable DImage on end of util.TraceLine
    3 replies, posted
Hello, So i have this code, but the problem is that when you are not looking at ent:GetClass() == "prop_physics" the image is still on screen. Simply i want to make when you are looking on prop - you see image, when you are not looking at it - you don't see it hook.Add("Think", "Wire", function()    for _, ply in pairs(player.GetAll()) do local tr = util.TraceLine( {     start = LocalPlayer():EyePos(),     endpos = LocalPlayer():EyePos() + EyeAngles():Forward() * 5000,     filter = function( ent ) if ( ent:GetClass() == "prop_physics" ) then local img = vgui.Create("DImage") img:SetSize(250,250) img:SetPos(ScrW()/2 - img:GetWide()/2,ScrH()/2 - img:GetTall()/2) img:SetImage("models/wireframe") end end} ) end end ) Any help would be appreciated, Thanks!
First of all, you are creating panels every frame, this is horribly wrong and you shouldn't be doing this, only create 1 panel and cache it, this way you also solve your problem of hiding it, which can be easily done by calling SetVisible( false ) on the variable you store the 1 DImage in.
You don't need to trace it with a tick trace, the player already does a trace. Throw the code in a HUDPaint if its only on the client, Player:GetEyeTrace().Entity:GetClass() can be used to compare classes. Your image is drawing because you didn't write the instruction to check if hes looking at the entity. With your current filter your actually restricting the trace from hitting any "prop_physics" entities.
Do be honest drawing with the draw/render library isnt a bad idea.
Sorry, you need to Log In to post a reply to this thread.