I’m confuse and unsure of
- How to use Lerp,
- Why use it,
- What to use it for
- When to use it.
What’s the benefit of using Lerp when you can use TweenService for example
I’m certain that you can use Lerp for Vector3 and CFrame but I’m unsure if Lerp is also available to other Roblox types, I can’t find a list anywhere that provides me with that information.
I read this Documentation - Roblox Creator Hub and to be honest it wasn’t really helpful but no hate towards the DevHub.
Hopefully people experienced with Lerp can answer my questions.
5 Likes
Lerp or linear interpolation is a simple function to linearly interpolate between 2 values. A good example of lerping between 2 numbers would be:
local i = 0.2 -- a value between 0 and 1, or origin and target
local v0,v1 = 5,8 -- the origin and target value
local v2 = v0 + (v1-v0)*i -- the result of interpolation
It doesn’t excel in everything, such as rotations which often require slerping to get perfect results, but it’s good enough as the cost of precision is a small price to pay for performance.
Why not use tween service? You need to create a new Instance for every tween, while Lerping just requires you to use a method implemented in the class you want to interpolate.
Also, I forgot to say that for anything that requires math formulas, using tweens would over-complicate things. You can easily use :Lerp() and everyone will understand it, while setting up a tween requires multiple lines of code.
22 Likes
Linear interpolation is used heavily in the creation of bezzier curves. Which essentially is a method to draw a curve between some amount of points.
4 Likes