Difference between lerping and tween?

Since tween and lerping are used to move objects why do some prefer the other then that? I really wanna know why and which is better to use.

1 Like

Tween Service is essentially an automatic lerp, however you have more control over a lerp. I made a nice tutorial which includes a section on lerping

3 Likes

Alright thanks will definitely read it!

1 Like

Yeah it contains some slightly more complex stuff so definitely read the Lerp part

1 Like

Tween is a service that roblox gives use to easily interpolate properties this can be any property we want and any instance type we want for instance we can tween BlurEffect.Size to make the screen slowly blur and unblur

we also have Tween.TweenInfo that allows us to customise the tweens most notably EasingStyle

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
	2,                         -- Time
	Enum.EasingStyle.Bounce,   -- EasingStyle
	Enum.EasingDirection.Out,  -- EasingDirection
	-1,                        -- RepeatCount (when less than zero the tween will loop indefinitely)
	true,                      -- Reverses (tween will reverse once reaching it's goal)
	0                          -- DelayTime
)
local blurEffect = game.Light.BlurEffect
local goal = {Size = 5}
local tween = TweenService:Create(blurEffect, tweenInfo, goal)
tween.Completed:Connect(function(playbackState)
	print("tween:", tostring(playbackState))
end)
tween:Play()

some of the datatypes have a Lerp function
Vector2:Lerp
Vector3:Lerp
CFrame:Lerp
Color3:lerp

this lerp functions allows you to interpolated between two values

here is how you can make your own lerp function

local function Lerp(value1, value2, alpha)
    return value1 + (value2 - value1) * alpha
end

print(Lerp(1, 2, 0.7)) -- 1.7

so if we had 2 vector3’s

local v1 = Vector3.new(0, 0, 1)
local v2 = Vector3.new(0, 0, 2)

and if we lerped these 2 vector3’s by 0.7 (0 = 0%, 0.5 = 50%, 1 = 100%)

local v3 = v1:Lerp(v2, 0.7)
print(v3) -- 0, 0, 1.7

we can see that v3 has moved 70% closer from v1 to v2


so what one is better to use?
well that’s like asking is it better to use a fork or a spoon each have there own strengths based on what your trying to do

tween is good for movements that are not dynamic and don’t need to always calculate a new goal for instance a door opening and closing you would make 2 tweens one for open and one for close and you would reuse the same 2 tweens over and over every time you want to open and close the door

Lerp on the other hand allows you to always move something closer to something else by a percentage for instance i can make parts1 position move 50% closer to parts2 position every heartbeat

if your moving parts with tween or lerp the part should always be anchored if the part is not anchored then you should always move parts with physics that can be done with things like
https://developer.roblox.com/en-us/api-reference/class/AlignPosition
https://developer.roblox.com/en-us/api-reference/function/BasePart/ApplyImpulse
there are many ways to control physics based parts

Roblox’s physics engine is very efficient and also send less data over the network you can find out more here:

5 Likes