New UDim2:Lerp method

Returns a UDim2 interpolated between the current UDim2 value and a goal UDim2 value by the fraction alpha. Similar to other Lerp methods eg. Vector3:Lerp()

Example:

print(UDim2.new(0, 0, 0, 0):Lerp(UDim2.new(1, 0, 1, 0), 0.5))
> {0.5, 0}, {0.5, 0}
57 Likes

Does it lerp the pixel offset values as well?

Yeah, just linearly interpolates each component

> for i=1,5 do print(UDim2.new(0,0,0,0):Lerp(UDim2.new(1,100,1,100),i/5)) end
{0.200000003, 20}, {0.200000003, 20}
{0.400000006, 40}, {0.400000006, 40}
{0.600000024, 60}, {0.600000024, 60}
{0.800000012, 80}, {0.800000012, 80}
{1, 100}, {1, 100}
4 Likes

lerp
Lerp
Make up your mind

10 Likes

Both versions work

2 Likes

Used to not be the case, my bad

So there’s another way to tween now?

Whatever floats your boat.

There’s always been a way to tween GUI.

TweenPosition and TweenSize and TweenSizeAndPosition

This just let’s us do custom stuff much easier.

As ScriptOn said, tweening doesn’t give you everything, and this makes it easier to fill in its gaps.

2 Likes

Just typed this up in sublime text real quick, but essentially if you wanted quick lerping this would be sufficient?:

function LerpUDim2(gui, property, start, finish, frames)
	gui[property] = start
	for i = 1, frames do
		gui[property]:Lerp(UDim2.new(1, 100, 1, 100), (i / frames))
		wait(0)
	end
	gui[property] = finish
end
LerpUDim2(gui, 'Position', UDim2.new(0, 0, 0, 0), UDim2.new(0, 120, 0, 120), 20)
2 Likes

Yeah, seems good

1 Like

I’m not entirely sure what you’re trying to do, but I think it’s wrong…
(you’re only using ‘finish’ at the end, you’re lerping on a value (field) that changes the whole time, …)
I thought it should be something like this:

local rs = game:GetService("RunService").RenderStepped
local function LerpProperty(obj,prop,start,finish,time)
	local t = tick()
	obj[prop] = start
	while true do
		rs:wait() -- using RenderStepped cuz smooth lookin'
		local p = (tick()-t)/time -- progressed time in %
		if p >= 1 then break end -- more than 'time' seconds passed
		-- can transform p to math.sin or some other lerp:
		p = p * p * (3 - 2*p)
		-- stole that formula from some site on google (link below code)
		obj[prop] = start:Lerp(finish,p)
	end
	obj[prop] = finish
end
LerpProperty(gui,"Position",UDim2.new(),UDim2.new(0,120,0,120),5)

Link to the lerping thing: https://chicounity3d.wordpress.com/2014/05/23/how-to-lerp-like-a-pro/
(it’s for Unity, but the (pure) mathematical formulas are more or less usable, if you change 2f into 2 etc)
That particular function results in this lerp thingy:

8 Likes

OKAY LISTEN HERE YOU LITTLE… thanks :smiley: :laughing: :laughing: :laughing:

mine was just writen in a few seconds a concept example to what the code would look like, but thanks for your code yo, that helps a lot friend :smiley:

+20 Thank-you Points to @einsteinK :cat:

6 Likes