Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Inertial rotation on a parented layer

  • Inertial rotation on a parented layer

    Posted by Tord-øystein Stubberud on June 3, 2018 at 2:40 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
    }

    Kalleheikki Kannisto replied 8 years, 3 months ago 2 Members · 3 Replies
  • 3 Replies
  • Kalleheikki Kannisto

    June 5, 2018 at 3:10 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

  • Tord-øystein Stubberud

    June 5, 2018 at 7:06 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.

  • Kalleheikki Kannisto

    June 5, 2018 at 7:58 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy