-
Dan Ebbert’s expression Boucing Ball + Squash & Stretch
Hi guys,
I found Dan Ebbert’s expression for the position of the boucing ball :Position :
e = .7;
g = 5000;
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
valueWorking pretty fine even if I doesn’t works with x & y dimension I think only bouncing on Y but I guess it’s part of the deal.
However I’d like to combine it with a scale expression like this one (from a previous expression) to make a squash and bounce :Scale :
Vy0 = 500; //initial y velocity (pixels/second)
Vx0 = 300; // initial x velocity (pixels/second)
g = 2500; // gravity (pixels/second/second)
floor = 400;
e = .85; //elasticityd = .02; //squash factor
spd= 10; //speed of squash oscillation
decay= 10.0; //how fast squash slows downb = floor – position.valueAtTime(0)[1];
h = b + Vy0*Vy0/(2*g);
T = Vy0/g + Math.sqrt(2*h/g);if (time < T){
x = scale[0];
y = scale[1];
}else{
Vy = -(Vy0 – g*T);
while (true){
max_dev = e*Vy*d;
Vy *= e;
t = T;
T += 2*Vy/g;
if (time < T){
t = time – t;
x=scale[0]+max_dev*Math.cos(spd*(t))/Math.exp(decay*t);
y=scale[0]*scale[1]/x;
break;
}else if (T – t < thisComp.frameDuration){
x = scale[0];
y = scale[1];
break;
}
}
}
[x,y]Working with this one
position :
Vy0 = 500; //initial y velocity (pixels/second)
Vx0 = 300; // initial x velocity (pixels/second)
g = 2500; // gravity (pixels/second/second)
floor = 400;
e = .85; //elasticityb = floor – position[1];
h = b + Vy0*Vy0/(2*g);
T = Vy0/g + Math.sqrt(2*h/g);if (time < T){
y = Vy0*time – g*time*time/2 + b;
}else{
Vy = -(Vy0 – g*T);
while (true){
Vy *= e;
t = T;
T += 2*Vy/g;
if (time < T){
t = time – t;
y = Vy*t – g*t*t/2;
break;
}else if (T – t < thisComp.frameDuration){
y = 0;
break;
}
}
}
[position[0] + Vx0*time, floor – y]I don’t know if I’m clear enough.
Let me know,
Cheers !