- Home /
Mathf.Lerp like User Define Function
As the title suggest, I want to create user define function like Mathf.Lerp. I want same functionality implementation as like Mathf.Lerp has.
I know Unity already provide this functionality but I want to create it for other game platform and want to achieve same functionality.
So what coding strategy behind this function I have to use??
Answer by Mayank Ghanshala · Aug 07, 2014 at 09:08 AM
Lerp is a static function which works like that
public static float Lerp (float from, float to, float t)
{
return from + (to - from) * Mathf.Clamp01 (t);
}
Clamp01 is also a static function which works like that
public static float Clamp01 (float value)
{
if (value < 0f)
{
return 0f;
}
if (value > 1f)
{
return 1f;
}
return value;
}
Answer by Issah · Aug 07, 2014 at 10:21 AM
Hi,
i past my answer from an other subject in accord with Siddhartha :
Lerp mean linear interpolation : http://en.wikipedia.org/wiki/Linear_interpolation
If you want a regular curve its an affine function like ax + b
I think you want a curve like a log, fast at start and slower with time, and when you'r close to the wanted value you stop your Roulette (cause Log never reach the final value) :
http://en.wikipedia.org/wiki/Logarithm
Mathf is an unity class which provide manny function to calcultate this type of curve :
http://docs.unity3d.com/ScriptReference/30_search.html?q=mathf
You can find the function of the log, manny graph and other mathematical usefull information :
http://en.wikipedia.org/wiki/Taylor_series
I hope it will help.