Skip to main content
Inspiring
February 22, 2014
Question

inertial bounce expression

  • February 22, 2014
  • 2 replies
  • 4688 views

hello everyone i have after effects cc and windows 8.

when i was on ae cs6 i used this expression and it worked perfectly

n = 0;

if (numKeys > 0) {

n = nearestKey(time).index;

if (key(n).time > time){

n--;

}

}

if (n == 0) {

t = 0;

} else {

t = time - key(n).time;

}

if (n > 0){

v = velocityAtTime(key(n).time - thisComp.frameDuration/10);

amp = 5;

freq = 1.0;

decay = 5.0;

value + (v/100)*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

}else{

value;

}

now on ae cc it works for 1 minute and then this error pops up:    (in this case i applied the expression on the position of a null object with linear velocity)

After Effects warning: an expression was disabled as a result of an error.

Error at line 19 'Position' of layer 2 ('Null 7') in comp 'Comp 4'.

invalid numeric result (divide by zero?)

how can i fix this error? that expression was very very helpful!

thx!

This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
February 22, 2014

With a decay of 5, Math.exp(decay*t) will overflow at about t = 142 seconds. You could just change this line:

if (n > 0){

to this:

if (n >0 && t < 10)

and it should work fine.

Dan

Inspiring
March 28, 2014

thx guys all your solutions works perfectly fine! this was really helpfull!

françois leroy
Inspiring
February 22, 2014

Hi!

I tried the expression and have no issue...

However, if it works fine most of the time, you can still put a "try {} catch ()" so the expression isn't disabled.

try{ // new line

n = 0;

if (numKeys > 0) {

n = nearestKey(time).index;

if (key(n).time > time){

n--;

}

}

if (n == 0) {

t = 0;

} else {

t = time - key(n).time;

}

if (n > 0){

v = velocityAtTime(key(n).time - thisComp.frameDuration/10);

amp = 5;

freq = 1.0;

decay = 5.0;

value + (v/100)*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t); //the error probably comes from here as it is the only division...

}else{

value;

}

}catch(e){value} // new line

Cheers,

François

UQg
Legend
February 22, 2014

Hi, it's probably because of the Math.exp.

You can try replacing value + (v/100)*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t); by

value + (v/100)*amp*Math.sin(freq*t*2*Math.PI) * Math.exp(-decay*t);

Alternatively replace

amp = 5;

freq = 1.0;

decay = 5.0;

value + (v/100)*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

by

amp = 5;

freq = 1.0;

decay = 5.0;

decay *= t;

decay > 70 ? value : value + (v/100)*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay);

Xavier.