Math.lerp
From GiderosMobile
Available since: Gideros 2026.1
Class: math
Description
Performs linear interpolation between two numbers using a factor.
(number) = math.lerp(a,b,t)
Generally returning the result of a + (b - a) * t.
When t is exactly 1, the value of b will be returned instead to ensure that when t is on the interval [0, 1], the result of lerp will be on the interval [a, b].
Parameters
a: (number) number value a
b: (number) number value b
t: (number) interpolation factor
Return values
Returns (number) linearly interpolated value
Example
application:setBackgroundColor(0x4e4e4e)
local pix = Pixel.new(0x00ffff, 1, 32, 32)
local current_position : number = 0
local target_position : number = 5*64
local speed : number = 0.1 -- determines how quickly it approaches the target
stage:addChild(pix)
pix:setPosition(current_position, 2*64)
local pix2 = pix:clone()
pix2:setColor(0xff5500)
stage:addChild(pix2)
pix2:setPosition(target_position, 2*64)
stage:addEventListener(Event.ENTER_FRAME, function(e)
if current_position > (target_position-0.001) then return end
current_position = math.lerp(current_position, target_position, speed * e.deltaTime * 30)
pix:setPosition(current_position, 2*64)
end)
See also
Optimizations#New_math.lerp_luau_function_.28it.27s_bad.21.29 🤷♂️
Ftf_snippets#LERP_.40xxx
- Math
- Math.abs
- Math.acos
- Math.asin
- Math.atan
- Math.atan2
- Math.ceil
- Math.clamp
- Math.cos
- Math.cosh
- Math.cross
- Math.deg
- Math.distance
- Math.distances
- Math.dot
- Math.edge
- Math.exp
- Math.fft
- Math.floor
- Math.fmod
- Math.frexp
- Math.ifft
- Math.inside
- Math.ldexp
- Math.length
- Math.lerp
- Math.log
- Math.log10
- Math.max
- Math.min
- Math.modf
- Math.nearest
- Math.noise
- Math.normalize
- Math.pow
- Math.rad
- Math.random
- Math.randomseed
- Math.raycast
- Math.round
- Math.sign
- Math.sin
- Math.sinh
- Math.sqrt
- Math.tan
- Math.tanh