• 3D2D Healthbar drawing on top of each other when it shouldn't
    3 replies, posted
The healthbar will be drawn in order of which one was actually drawn first instead of which one is closer to the viewer. Here's the code I'm using: hook.Add("PostDrawTranslucentRenderables", "DrawHealthBar", function()      local ply = LocalPlayer()      for _,v in pairs(ents.GetAll()) do           if(!v:IsNPC() || v:IsNPC() && v:GetNWBool("IsDead") == true) then continue end           local center = v:OBBCenter()           local scale = v:OBBMaxs()           local _, maxBound = v:GetRenderBounds()           local height = math.Max(maxBound.Z*0.9, scale.Z)           local pos = v:GetPos() + Vector(center.X, center.Y, height)           local ang = Angle(0, EyeAngles().Yaw - 90, 90 )           cam.Start3D2D(pos, ang, scale.X/25)           surface.SetDrawColor(255, 255, 255, 255)           surface.SetMaterial(Material("vgui/MoveSlot.png"))           surface.DrawTexturedRect(-50, -20, 100, 20)           cam.End3D2D()      end end) https://i.gyazo.com/e0fabeb22d7ac0cc61f47222d3e26278.jpg
You'll have to iterate over each entity you want to draw the display for, in order of closest to furthest. So you could construct a table with all the entities you want to draw, sort it by distance, then do another loop over that newly created table and do your drawing. Should solve your issue.
That was the original idea but I wanted to wait for some "Magic sorting command". Sorting tables in lua is super slow ._.
none that i know of, sorry.
Sorry, you need to Log In to post a reply to this thread.