I decided to write a module for handling linear interpolation, as I find myself needing it pretty frequently. I assume you, the reader, might also benefit from this, so I attached the code.
If you don’t know what linear interpolation is, it’s smoothly transitioning from one value to the next.
Here’s the syntax
Lerp(rbx, prop, target, duration?, callback? easingStyle?, easingDirection? is_relative?)
- rbx: the object you are targeting.
- prop: the property you want to smoothly change.
- target: the value that you want it to change it. Note, if ‘is_relative’ is true, the value will be considered as an offset. The resulting value will thus be startValue + target, instead of target.
- duration: how long the lerp takes to finish.
- callback: a function which is called when the lerp is done. rbx is passed as a parameter.
- easingStyle: specific function by which to smooth the transition. Use Enum.EasingStyle.
- easingDirection: Use Enum.EasingDirection. Decides whether the easing is applied to the start/end, or both.
- is_relative: again, determines if target is an absolute value to lerp towards, or if it’s an offset from the current value
require(game.ReplicatedStorage.Lerp)(workspace.Part, 'Position', Vector3.new(0,10,0), 3, function(self) self:Destroy() end, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, true)
Lerp.lua (8.3 KB)