Ease In / Ease Out Algorithm

5c40dec1f01e5ece1503ed08c330a6d1
0
thespongebob 101 May 23, 2008 at 03:40

Hi
My math is pretty basic. I have books but not much practice in application yet.
Here is what I want to do.

I have 30 frames to work with.
I need an output value between 0.0f and 4.0f to apply a “shake” to an object within that 30 frames.
I want the shake to ease in and ease out.

Could someone point me in the right direction?

3 Replies

Please log in or register to post a reply.

B99b270b02792e7919f45d19720eb206
0
Omni 101 May 23, 2008 at 07:31

why don’t you simply use the good old (co)sinus?
if you combine two near frequencies
f_1 = f_0 - d
f_2 = f_0 + d
you get a beat of frequency d:

so your function could look like this: f(t) = 2.0 * ( cos( (f_0 + (Pi/30)) * t ) - cos( (f_0 - (Pi/30)) * t ) )
f_0 is your shake oscillation and should be much larger than Pi/30

th\_29179\_schwebung\_122\_543lo.jpeg

6b7e1a4b42e4b47d92fdef8bf2bd8e2c
0
Jare 101 May 23, 2008 at 07:53

@thespongebob

I have 30 frames to work with.
I need an output value between 0.0f and 4.0f to apply a “shake” to an object within that 30 frames.
I want the shake to ease in and ease out.

Sounds like a case for the classic cubic S-curve, which takes an input from 0 to 1 and outputs a value from 0 to 1 that is horizontal at both 0 and 1:

s(x) = 3*x\^2 - 2*x\^3 (note, a\^b means a to the power of b)

so if your shake value eases in from 0 at frame 0 to max value at frame A, then stays at max until frame B, then and eases out from max value at frame B to 0 at frame 30:

shake(f) =
if f < A: return s(f/A)
if f > B: return 1.0 - s((f-B)/(30-B))
return 1.0

and multiply the output by 4.0 which is your desired max value. I love that little function. Other alternatives:

s(x) = sin(x*PI/2)\^2 is slightly smoother
s(x) = x - sin(x*2*PI) / (2*PI) is noticeably smoother

Try them in for example http://rechneronline.de/function-graphs/ to see what they look like.

that represents the “amplitude” of the shake, and then somewhere else you generate some vibration using that amplitude (probably some kind of cos() like Omni suggests) with a frequency of your choosing.

5c40dec1f01e5ece1503ed08c330a6d1
0
thespongebob 101 May 23, 2008 at 18:07

Thanx Jare. That is exactly what I wanted. That site is a great help to actually visualize what I am doing. I want to have a user-interface (health hud) shake/grow when a bullet hits my avatar.