Hello! I have seen that a lot people just does not know how to make smoothly animatedhealthbar.
This is a short tutorial on how to make it.
This is very easy, just 3-4 lines!
I made a simple health bar to show you how it works.
This method using math.Approach().http://wiki.garrysmod.com/page/math/Approach Basically this function is making current value closer to a new value by a number in last argment. By putting it in HUDPaint hook it will change it every frame. With this you can make any animations you want in GMOD. WARNING! Always place "hpe = 0" or simmilar outside the hook. Otherwise your healthbar will not work because it will always return to 0.
Code:
hpe = 0 -- Needs to be always outside the hook hook.Add("HUDPaint", "Test", function() if !LocalPlayer():Alive() then return end -- Removing hud when player dead hpe = math.Approach( hpe, LocalPlayer():Health(), 2 ) -- 2, the last arg, is speed draw.RoundedBox(3,20, ScrH()/2, hpe*2, 20, Color(255,0,0)) -- Drawing HP box draw.SimpleText(""..hpe, "DebugFixed", 20, ScrH()/2, Color(255,255,255,250) ) -- Drawing a little hp number