• | **Inertia expression keeps turning itself off**
on Dec 1, 2011 at 12:23:38 pm |

Hi there

I'm working on a big project at the moment and I'm using this inertia (bounce) expression on lots of elements. It's an expression I found online at the Motion Graphics Exchange website.

When the expression works, it works a treat but it constantly turns off and throws the following error:

After Effects warning: invalid numeric result (divide by zero?)

Expression disabled.

If anyone can help out here, I'd really, really, really appreciate it as it's becoming quite painful and the deadline looms.

Thanks in advance :)

Mike

`// Inertial Bounce (moves settle into place after bouncing around a little)`

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 = .03;

freq = 1;

decay = 15;

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

}else{

value;

}

miketosetto dot com | bestiacollective dot com

• | **Re: Inertia expression keeps turning itself off** on Dec 1, 2011 at 3:44:18 pm |

My guess is that the value of t must be getting large enough to cause the Math.exp() function to overflow. How far into the comp do you get the error (and what is the line number in the error message)?

Dan

• | **Re: Inertia expression keeps turning itself off** on Dec 1, 2011 at 9:06:02 pm |

Hi Dan, thanks for getting back to me about this.

The AEP is getting quite big now and it's about 2 mins long and growing. I'm using this expression on about 100 layers or so and often the layers are in pre comps of about 50 layers so it's a reasonable project in size.

When AE throws the error, it tells me the layer name and says it occurs at line 20 so I think you're spot on with thinking it's to do with this part: Math.exp(decay*t);

Can it be fixed or written a different way? Do you have any suggestions?

Thanks for your help Dan, I really appreciate it mate.

Cheers

Mike

miketosetto dot com | bestiacollective dot com

• | **Re: Inertia expression keeps turning itself off** on Dec 1, 2011 at 9:20:49 pm |

Try changing the first line of the last section from this:

if (n > 0){

to this:

if (n > 0 && t < 1){

Dan

• | **Re: Inertia expression keeps turning itself off** on Dec 2, 2011 at 8:53:28 am |

Dan, YOU ARE AMAZING!!!

Solved the problem and I was able to work all day and hit my deadline. Like I said, I owe you a beer...

Hats off mate, can't believe you solved it

Thanks again

Mike

miketosetto dot com | bestiacollective dot com

• | **Re: Inertia expression keeps turning itself off** on Feb 6, 2012 at 3:58:45 pm |

Thanks for this reply.. this was driving me mad!

I think this has solved my problem too

Cheers! :)

• | **Re: Inertia expression keeps turning itself off** on Jun 2, 2012 at 12:07:24 pm |

Well, this poisoned an ongoing project I have for two months, I have been looking for the solution everywhere and here it is. But who else than Dan could have solved this? I worship at your feet Daniel.

Cheers

Jean

• | **Re: Inertia expression keeps turning itself off** on Feb 8, 2013 at 11:56:21 am |

thanks!

MG

• | **Re: Inertia expression keeps turning itself off** on Feb 4, 2015 at 3:05:54 pm |

Dan I have the same problem but with a little difference , could you help me with this?:

I try use your solution :

if (n > 0){

to this:

if (n > 0 && t < 1){

but this no works in this case:/

`amp = .2;`

freq = 3;

decay = 2;

kf = 2; // only on 2nd keyframe

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time) n--;

}

if (n == kf){

t = time - key(n).time;

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

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

x = temp[0];

y = value[0]*value[1]/x;

[x,y]

}else

value

• | **Re: Inertia expression keeps turning itself off** on Feb 4, 2015 at 5:17:55 pm |

try changing this:

if (n == kf){

to this:

if ((n == kf) && (t < 5)){

Dan

• | **Re: Inertia expression keeps turning itself off** on Feb 4, 2015 at 10:46:31 pm |

There is an error on this line :/:

"Class global has no property or method named "t"

• | **Re: Inertia expression keeps turning itself off** on Feb 4, 2015 at 10:51:13 pm |

Ah yes, sorry.

you need to also move the definition of t outside the conditional. So change this:

if (n == kf){

t = time - key(n).time;

to this:

t = time - key(n).time;

if ((n == kf) && (t < 5)){

Dan

• | **Re: Inertia expression keeps turning itself off** on Feb 4, 2015 at 10:59:08 pm |

Nah, that's not going to work either. Give me a minute...

Dan

• | **Re: Inertia expression keeps turning itself off** on Feb 4, 2015 at 11:05:02 pm |

That's what I get for not testing it. This should work:

amp = .2;

freq = 3;

decay = 2;

kf = 2; // only on 2nd keyframe

n = 0;

if (numKeys > 0){

n = nearestKey(time).index;

if (key(n).time > time) n--;

}

if (n == kf){

t = time - key(n).time;

if (t < 5){

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

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

x = temp[0];

y = value[0]*value[1]/x;

[x,y]

}else{

value

}

}else

value

Dan

• | **Re: Inertia expression keeps turning itself off** on Feb 5, 2015 at 3:53:05 pm |

How forever thanks Dan!!! :D this works perfect and you saved me a lot of time and problems.

• | **Re: Inertia expression keeps turning itself off** on Apr 18, 2013 at 1:58:16 am |

This is a lifesaver for an AE newbie. Thanks