Using a Bounce Expression?
I animated a .png of an item falling, and rotating as it falls until it hits the floor. After the animation ended, I moved the CTI a few frames ahead and rotated it a bit to add a new keyframe, and moved the CTI again and rotated it again to make it seem more like a bounce when it hit the ground. I want to make the bounce seem a bit more natural. I spent some time online and I read about Expressions, and I copied some Bounce Expression that I found, and I want to paste it so I press alt and clicked on the Stopwatch for Rotation to paste the Expression since this is the last thing that I added to the animation. The Expression editor opens with
transform.rotation
When I paste the following Bounce Expression after this it just gives me an error.
“This project contans an expression error: error 1 of 1. What am I doing wrong? Thanks in advance!
e = .5;
g = 20000;
nMax = 9;
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n–;
}
if (n > 0){
t = time – key(n).time;
v = -velocityAtTime(key(n).time – .001)*e;
vl = length(v);
if (value instanceof Array){
vu = (vl > 0) ? normalize(v) : `{`0,0,0`}`;
}else{
vu = (v < 0) ? -1 : 1;
}
tCur = 0;
segDur = 2*vl/g;
tNext = segDur;
nb = 1; // number of bounces
while (tNext < t && nb <= nMax){
vl *= e;
segDur *= e;
tCur = tNext;
tNext += segDur;
nb++
}
if(nb <= nMax){
delta = t – tCur;
value + vu*delta*(vl – g*delta/2);
}else{
value
}
}else
value
