Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Auto secondary movement (inertia/overshoot) in children layers

  • Auto secondary movement (inertia/overshoot) in children layers

  • Eduardo Oliveira

    April 26, 2016 at 2:57 pm

    sorry, i forgot aobut the -1

    here is the correct version:

    //inertial children bounce
    n = 0;
    amp = .04;
    freq = 2.0;
    decay = 3.0;

    ppos=thisLayer.parent.transform.position;
    if (ppos.numKeys > 0){
    n = ppos.nearestKey(time).index;
    if (ppos.key(n).time > time){
    n--;
    }
    }
    if (n == 0){
    ppos.velocity
    t = 100;
    }else{
    t = time - ppos.key(n).time;
    }

    if (n > 0){
    v = ppos.velocityAtTime(ppos.key(n).time - thisComp.frameDuration/10);

    value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
    }else{
    value
    }

  • Jake Dickey

    April 26, 2016 at 3:11 pm

    Like a boss! Thank you! This has been really helpful in learning how to reference other layers’ properties properly. I was actually able to figure out how to make it work on an older version of the classic “bounce” expression BEFORE someone added in the amp variable,

    freq = 3;
    decay = 5;

    ppos=thisLayer.parent.transform.position;
    n = 0;
    if (ppos.numKeys > 0){
    n = ppos.nearestKey(time).index;
    if (ppos.key(n).time > time) n--;
    }
    if (n > 0){
    t = time - ppos.key(n).time;
    amp = ppos.velocityAtTime(ppos.key(n).time - .001);
    w = freq*Math.PI*2;
    value + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
    }else
    value

    …but I couldn’t figure out how to make it work on the version of the expression that I had WITH the amp variable. Thanks for letting me pick your brain a bit!

  • Tim Drage

    April 27, 2016 at 11:06 am

    These are great and I too have been looking for something like this for ages, thanks!!!

  • Eduardo Oliveira

    April 27, 2016 at 11:22 am

    Was glad to help, Guys.

    anyways, just for the sake of people that end up on this thread in the future, i’ve collated the most revised versions below, so that people can use the right ones without having to re-read the whole thread.

    (these are 2 different expressions, use the one that suits your needs)

    //inertial children bounce (apply on "position")
    n = 0;
    amp = .04;
    freq = 2.0;
    decay = 3.0;

    ppos=thisLayer.parent.transform.position;
    if (ppos.numKeys > 0){
    n = ppos.nearestKey(time).index;
    if (ppos.key(n).time > time){
    n--;
    }
    }
    if (n == 0){
    ppos.velocity
    t = 100;
    }else{
    t = time - ppos.key(n).time;
    }

    if (n > 0){
    v = ppos.velocityAtTime(ppos.key(n).time - thisComp.frameDuration/10);

    value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
    }else{
    value
    }

    //inertial children rotation (apply on "rotation", for dagling things like earrings, dreadlocks, pendants etc)
    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
    }

  • Tim Drage

    April 27, 2016 at 3:13 pm

    Thanks again, having a play with this 🙂

    Two things i’d like to try if i can get my head around it and/or if even possible:
    * modifying to make it operate in world space to make chains of dangling things 🙂
    * making it so that it doesn’t clamp at 90°, ie so that the thing can spin right round and dangle up if the object is descending… don;t actually know if that makes any sense vs how the expression works tho.

    Will post any edited versions i manage to do anything interesting with, tho maybe you or someone else might have an easy answer to the above? 🙂

  • ricardo martins

    August 9, 2020 at 12:49 pm

    Sorry to bother you, but is there a way to make it affect the children’s rotatio be affected by the parent’s X and Y positioning? I’m quite new to expressions, couldn’t figure it out

    I’m trying to make some hair on a character move automatically with the head movement.

    Is it possible to make it check for parent’s position and rotation as well?

  • Eduardo Oliveira

    August 9, 2020 at 1:21 pm

    Hey Ricardo, how are you controlling the hair at the moment? is it on puppet pins? or jsut a layer on its own?

  • Sami Bayley

    September 14, 2021 at 3:18 pm

    Hey Eduardo! Does this not work with any easing?

  • Sami Bayley

    September 14, 2021 at 3:19 pm

    I also would love to add a delay to this, I’ve got a layer parented to another “leader” layer. Said leader layer has some position keyframes, the inertia effect is working great, however, I’d like the child layer to also have some delay. I’m pretty new to expressions so am still trying to figure it all out!

    What I’ve tried is using this expression:

    delay = .03;
    parent.fromWorld(toWorld(anchorPoint,time-delay))

     

    Along with adding this to yours:

     

    //inertial children bounce (apply on "position")
    n = 0;
    amp = 4;
    freq = 1;
    decay = 4;
    delay = .03;

     

    For some reason its just not doing what I want it to do!

     

Viewing 21 - 29 of 29 posts

Log in to reply.

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