Theres currently a luau RFC open for math.lerp
How is this useless, I find myself writing the same function over and over again and I would like a function that eases this need and speeds my productivity. Such a bold and thoughtless claim.
I agree with this request. If thereâs a cframe.lerp, surely we can have a math.lerp
iâm not so sure about this one
idk what kind of code you work on but there are definitely places where lerp gets used a lot
poor reasoning
this update should take like 1-2 minutes max
what is 1-2 minutes gonna do to the bigger updates? practically almost nothing. the âtiny bitâ of delay probably wonât even amount to 0.1% of the time
as for why theyâre slow with big updates, itâs partially a lack of âwanting to do itâ (aka procrastinating), partially a lack of idea on what they want to do,
or maybe theyâre encountering errors (those things are physically painful in c and c++, they will spam multiple verbose compile errors up your face all because you forgot a semicolon)
math.map
is already live in studio. It is an extension of lerp.
--format
local output = math.map(input, input_min, input_max, output_min, output_max)
--lerp
local value = math.map(alpha, 0, 1, from, to)
--example
local celsius = math.map(fahrenheit, 32, 212, 0, 100)
Letâs go, they need to add it to the documentation and maybe present it officially.
Wow. This mapping will definitely simplify many scripts in the near futureâsliders specifically come to mind.
Out of curiosity, how did you discover math.map
?
It has existed since October 18th. Funny that it was in RFC hell for 4 weeks but was added in just two days.
math.lerp
is still useful both for performance and showing intent. Iâd also like to see a vector.lerp
to mirror Vector3:Lerp
.
Yeah I figured it would be in Robloxâs GitHub repository; I was wondering how they initially found out about it. I donât think it was formally announced in the Forum, so is it just by checking the repository frequently you and @Prototrode discover these things?
This shouldnât be a problem; to restore the pretty slight performance edge of a normal lerp, the math.map
function can check if theyâre only three arguments. If so, then
return A + ((B - A) * D)
Yeah, I agree with this. It would make more sense linguistically than âmapâ in certain cases where itâs only functioning as a lerp. Plus it maintains consistency with other functions using the term lerp.
We just see them on the releases (that be Roblox or Luau).
Alternatively, if youâd like to be on top of everything Luau related, you can watch the repository or join the Roblox OSS Discord Server.
Frigginâ schweet update, canât wait for math.lerp
next
I literally said math.map
is an extension of lerp why would we still need lerp lol
It does what lerp does and then some more
Mb, I read it incorrectly, didnât even notice the lerp example
I donât see math.map as a replacement for math.lerp, specifically because of the âand then some moreâ part of it. Thereâs no reason to have that extra overhead when it explicitly is not needed.
The way I see it, math.map
automates the extra steps you would do anyways when using lerp. The lerp function accepts a scalar called alpha that is usually in the interval [0, 1]. How do people get any aribitrary value to be in that interval? They use inverse lerp first, and then use lerp again. math.map
is just that; ilerp and lerp glued together. But I get it, not everyone does this, and many times you immediately decide what alpha should be in the code.
Yes, I agree, but abstracting lerp into a function will still carry an overhead. Most people use lerp repeatedly for the same input parameters where the only changing value is the alpha. Common example is tweening without using the TweenService. If you take a look at the formula for linear interpolation:
value = start + (finish - start) * alpha
The expression (finish - start)
is a constant. There is no need to recompute it over and over again if start
and finish
are the same. So if you truly cared about performance and overheads, you wouldnât want to turn lerp into its own function; it gives you no room to optimize it for your specific use cases. If you took the extra effort to write the entire formula out, you at least have the opportunity to precompute finish - start
.
value = start + delta * alpha
TL:DR; math.map
is a practical replacement for lerp, and if you care about performance, you still wouldnât want lerp to be its own function.
math.lerp is still helpful
especially for people that donât know their math as well or are following a tutorial of some sort and boom, an easy implementation of lerp.
Whatâs a bit disappointing with math.map
is its roughly 10.5x slower than a native implementation (because itâs a raw VM call, not fastcalled).
Honestly, since a math.lerp
function would suffer the same problem, there would be no point in adding it either. Even if they fastcalled it (highly unlikely), it still would probably perform worse.
I really donât understand the frustration behind this. This is a very convenient feature.