n0mad
November 8, 2009, 11:41pm
1
Hello,
Well, there’s a SmoothDamp that eases a value in and out over time,
a SmoothStep that makes the same without velocity and time parameter,
a PingPong, a Lerp, a SmoothLerp, a DoSomeMagic (errr no wait …),
but there’s not the most used 2 functions in animation history :
Ease In, and Ease Out.
Any plan to implement it ?
(without having to import a full custom framework I mean, and with as much cool parameters as with SmoothDamp ^^)
Eric5h5
November 8, 2009, 11:48pm
2
n0mad
November 9, 2009, 10:18am
3
Thanks Eric, but I’m quite afraid by Sin / Cos operations on iPhone
As Easin In / Out is a spamming operation, I believe simple operations (add, multiply, divide, etc) should be less perf hungry.
Maybe I’m wrong ?
Actually, I found a way to deal with it :
newFloat = Mathf.Lerp(
minValue, MaxValue,
(((maxValue-minValue)/duration)*Time.deltaTime)*_acceleration
);
where _acceleration is the easeIn or easeOut.
(2-(2LerpPosition)) for easeOut,
(2 LerpPosition) for easeIn.
I tweaked startValue endValue of this acceleration to make it smoothier, and it seems to work fine.
But still, is Sin / Cos more hungry than such a chain of operations ?
Thanks for your help
n0mad
November 9, 2009, 8:43pm
4
confirmed :
using simple operations is 300% faster.
this one is 0.0030 seconds on my mac :
Mathf.Lerp(_from, _dest, Mathf.Sin(_value * Mathf.PI * 0.5f))
Here are my homemade functions (which means they won’t necesslarly fit everybody’s needs), they are 0.0010 seconds :
float _easeBaseSpeed = 1.5F; //initial acceleration
float EaseOut(float _from, float _dest, ref float _value, float _duration) {
float _result = _from+((_dest-_from)*_value);
float _accel = ((2F-(2F* _value))+(((_value*2F)-1F)*(2F-_easeBaseSpeed)));
_value += Time.deltaTime*((Mathf.Abs(_dest-_from))/_duration)*_accel;
return _result;
}
float EaseIn(float _from, float _dest, ref float _value, float _duration) {
float _result = _from+((_dest-_from)*_value);
float _accel = ((_value*2F)+((1F-(_value*2F))*(2F-_easeBaseSpeed)));
_value += Time.deltaTime*((Mathf.Abs(_dest-_from))/_duration)*_accel;
return _result;
}
1 Like