-
Inertial rotation on a parented layer
Hi, a couple of years ago I came across this expression, here on these forums, that adds inertial rotation to a child layer based on the position of its parent. It works great, but has a few limitations that I have been trying to figure out how to fix, but I am just not experienced enough with expressions. The limitation is that it only works when the parent layer moves on the X axis. I am wondering if there is a way to make it work on the Y axis as well….and maybe even be affected by the parent layers rotation? If someone wants to take a look, I would appreciate it very much! thanks!
n = 0;
amp = .04;
freq = 2.0;
decay = 3.0;ppos=thisLayer.parent.transform.position;
parv=clamp(ppos.velocity[0]*amp,-90,90)
if (ppos.numKeys > 0){
n = ppos.nearestKey(time).index;
if (ppos.key(n).time > time){
n--;
}
}
if (n == 0){
ppos.velocity[0]
t = 100;
}else{
t = time - ppos.key(n).time;
}if (n > 0){
v = ppos.velocityAtTime(ppos.key(n).time - thisComp.frameDuration/10)*-1;parv + v[0]*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
parv
}