ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Continuous bounce

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kenji Takahashi
Continuous bounce
on Jun 29, 2020 at 11:36:20 pm

Hi I need help with the "famous" bounce expression. It`s interesting problem and I`m scratched out.

Because frequence and decay are low ( I need it to be extra elastic) it only work for two keyframes.
On keyframe 3 it snaps in its value and sometimes on keyframe 4, 5, 7, 9.. depending on the nearest key index I presume
I`m trying valueAtTime but I`m limited with knowledge.

I need my keyframes not to be precise but relative to previous inherited velocity.

Thnx

freq = 0.5;
decay = 1;

n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 0){
t = time - key(n).time;
amp = velocityAtTime(key(n).time - .001);
w = freq*Math.PI*2;
value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}else
value


Return to posts index

Dan Ebberts
Re: Continuous bounce
on Jun 30, 2020 at 6:32:12 am

See what this version does for you:


freq = 0.5;
decay = 1;
val = value
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 1){
amp = velocityAtTime(key(n).time - .001);
w = freq*Math.PI*2;
for (i = 2; i <= n; i++){
t = Math.min(time - key(i).time,10/decay);
amp = velocityAtTime(key(i).time - .001);
val += amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}
}
val



Dan



Return to posts index

Kenji Takahashi
Re: Continuous bounce
on Jun 30, 2020 at 11:33:11 am

Absolutely beautiful, thank you Dan,
you sir are a gentleman and a scholar!




It will take hours to see what you did there :)


Return to posts index


Dan Ebberts
Re: Continuous bounce
on Jun 30, 2020 at 12:47:36 pm

This is slightly better:


freq = 0.5;
decay = 1;
val = value
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 1){
w = freq*Math.PI*2;
for (i = 2; i <= n; i++){
t = time - key(i).time;
if (t > 10/decay) continue;
amp = velocityAtTime(key(i).time - .001);
val += amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}
}
val



Dan



Return to posts index

Kenji Takahashi
Re: Continuous bounce
on Jun 30, 2020 at 1:42:22 pm

Yeah this one is cleaner.

I was actually looking for solution to do this.



I call it inertial animation. (or Ice animation ☺ )
Basically with the tweak in frequency and decay I can make inertia in movement without null parenting, with fever keyframes and without tweaks to keyframe velocity.
Example above was done with the code below and just easing first keyframe of movement. (animation must be done in linear fashion, forward, keyframe by keyframe. Just like pushing hockey puck on ice)

Once again thanks Dan!

freq = 0.001;
decay = 0.6;
val = value
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 1){
w = freq*Math.PI*2;
for (i = 2; i &lt;= n; i++){
t = time - key(i).time;
if (t > 10/decay) continue;
amp = velocityAtTime(key(i).time - .001);
val += amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}
}
val


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]