ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Inertial rotation on a parented layer

FAQ   •   VIEW ALL
 Inertial rotation on a parented layer on Jun 3, 2018 at 2:40:26 pm

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
}

 Re: Inertial rotation on a parented layeron Jun 5, 2018 at 3:10:38 pmLast Edited By Kalleheikki Kannisto on Jun 5, 2018 at 3:13:06 pm

Yes, that's pretty simple.

First of all, the line ppos.velocity[0] is unnecessary, you can delete it.

The code works on separated dimensions, so for Y you need to change the two remaining [0] values to [1].

(If you needed Z values, you'd put [2] there.)

For rotation, you just delete both [0] and replace the line
ppos=thisLayer.parent.transform.position; with
ppos=thisLayer.parent.transform.rotation;

Kalleheikki Kannisto
Senior Graphic Designer

 Re: Inertial rotation on a parented layeron Jun 5, 2018 at 7:06:22 pm

amazing! thanks for the response! So I know there is a way for this to work on several axis now. In my original post I was actually wondering if there would be a way for this expression to allow inertia on X and Y simultaneously, maybe with a slight tweak so that inertial movement on Y is slightly "muted", but your post puts me alittle closer to that. Thanks.

 Re: Inertial rotation on a parented layeron Jun 5, 2018 at 7:58:47 pm

Yes, just use them on separated Y and Y axis, and you can tweak different settings for both, since it's two separate expressions.

Kalleheikki Kannisto
Senior Graphic Designer