Copy link to clipboard
Copied
//The below script creates jiggle for keyframes in any property but sometimes
//results in attached error
//Can someone please help me with this
Thanks
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 = .05;
freq = 2.0;
decay = 5.0;
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
value;
}
Thanks in advance !!
Does your comp have a long duration between keyframes (or after the last keyframe)? If so, you might need to limit the "t" variable so that Math.exp doesn't overflow. Try changing this line:
t = time - key(n).time;
to this:
t = Math.min(time - key(n).time,10);
Dan
Copy link to clipboard
Copied
And what specifically are you asking? From a quick glance I'd simply say the loop decrements to zero if there are less than two keyframes. Unlike arrays, keyframe indices start at 1. Once you introduce the wrong index, of course all consecutive calculations will fail.
Mylenium
Copy link to clipboard
Copied
Does your comp have a long duration between keyframes (or after the last keyframe)? If so, you might need to limit the "t" variable so that Math.exp doesn't overflow. Try changing this line:
t = time - key(n).time;
to this:
t = Math.min(time - key(n).time,10);
Dan