I am trying to make a script in which a given number, eg 300 falls to 200 in a specific case, but to do it smoothly, not suddenly jump from 300 to 200. I have tried to use Lerp and Math.approach, but it is not suitable, but I do not know how to use it.
This number determines the width of the RoundedBox, I try to do something like the panel:SizeTo, but on RoundedBox without creating panel.
https://www.youtube.com/watch?v=OeXt3WknAoA
If you want to make the number move smoothly on a draw hook or function, you should create a variable stored outside of the hook or function and use FrameTime (multiplied by the velocity) in the first argument of Lerp or the third argument of math.Approach, and on the establish what number to go to
For example
If you want to lerp health you'd go with something like this
local health = 0
hook.Add("HUDPaint", "PaintHook", function()
// Example withy Lerp
health = Lerp(FrameTime() * 5, health, LocalPlayer():Health())
// Example with math.Approach
health = math.Approach(health, LocalPlayer():Health(), FrameTime() * 5)
end)
I used this in the HP bar and it works fine, but now I do not know how to use it correctly.
Currently, the script looks like this:
local width = 310
local height = 130
if (not client:Alive()) or client:Team() == TEAM_SPEC then
if hook.Call( "HUDShouldDraw", GAMEMODE, "TTTSpecHUD" ) then
-- SpecHUDPaint(client)
width = Lerp( 5 * FrameTime(), width, 200 )
end
end
local x = 10
local y = ScrH() - height - x
DrawMaterialBox(x, y, width, height)
And the end result looks like this:
https://www.youtube.com/watch?v=l1iUONrrWxA&feature=youtu.be
Sorry, you need to Log In to post a reply to this thread.