# 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

6 Members · 28 Posts
• ### Gergely Szilard

February 22, 2016 at 11:09 am

Hi. I’ve been searching for this for a while without any results, so I’ve decided to try my luck here – I always end up on cow anyway, when I’m researching AE 😛

I have a character to animate, that has a lot of dangling accessories on the head and body. My question is, is it possible to have those show inertia (basically sort of a rotation overshoot animation) using an expression, when the parent layer moves?

The (obvious) idea is to not have to do those manually, so I can work on my main animation more easily. Any input is welcome. Thanks.

• ### Eduardo Oliveira

February 24, 2016 at 10:07 pm

i think i got something here:
i did it only considering lateral movement, so you wouldnt see any inertial rotation for y axis movements.
but it works well with dangling things…
here is the code:

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

``` ppos=thisLayer.parent.transform.position; parv=clamp(ppos.velocity[0]/10,-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 } ```

• ### Gergely Szilard

February 26, 2016 at 2:25 pm

WOW man, this works great. I’m just getting into expressions and I’m constantly amazed of what they can achieve. Also, there’s some serious math going on in there that I would’ve never figured out by myself.

But I did manage to add some randomness so all dangly things don’t move at once and in the same measure, and that makes it look even better and really brings the character to life in no time (which is a rasta character with hanging jewelry and dreadlocks btw) and cuts down a LOT on secondary animation time, which is now pretty much automatic, thanks to you 😀

Later I’ll hook up the randomness and other variables to sliders and that’ll make my work even easier throughout the process.

Thank you for your tremendous help!

• ### Eduardo Oliveira

February 26, 2016 at 2:45 pm

forgot to say: you can adjust the parameteres to make small differences:
amp = this is how much of an overshoot will happen (higher = stronger)
freq= frequency of the swings ( higher = quicker swings)
and decay = how long before they come to a stop (higher = stops faster)

by tweaking those three you should be able to add enough variance.. also i made a slight tweak:
here is the revised one. let me know if it works well

```//inertial children 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 }```

• ### Eduardo Oliveira

February 26, 2016 at 2:54 pm

Ps: the “serious math” wasn’t figured out by myself too 🙂
I took the famous Inertia bounce expression ( I think it was made by Dan Ebberts, orinally)
and just modified to suit your needs 🙂

• ### Gergely Szilard

February 28, 2016 at 11:24 am

I have come across the original inertia bounce script myself, but I didn’t know how to access the parent’s keyframe data, didn’t even know if it’s possible. The variables are pretty self-explanatory, I got that part.

I still haven’t had enough time to work on this properly, but I added a little something to the code to delay the reaction of some of the parts by a few frames (20 in my example), to sort of simulate their weight. I don’t know however if this is the right way to go about it, or maybe there is a better way?

`v = ppos.velocityAtTime((ppos.key(n).time - thisComp.frameDuration*20) - thisComp.frameDuration/10)*-1;`

• ### Eduardo Oliveira

February 28, 2016 at 11:32 am

changing the “v” variable might give you wrong/weird results..

try changing the “parv” variable instead to below: ( although 20 is a bit overkill)

although in my opinion the best way to simulate wheight is the freq variable. heavier items should just have lower values.

i haven’t tested this tweak, se let me know if it works 🙂

`parv=clamp(ppos.velocityAtTime(time- thisComp.frameDuration*20)[0]*amp,-90,90)`

• ### Gergely Szilard

March 8, 2016 at 10:26 am

Hey.
I’ve been neglecting this project because I didn’t have any time, but now I’m back on it 🙂

You’re right, the existing variables are more than enough for what I need, so I’m pretty much gonna keep the code as you wrote it, it works great. I only lowered the clamp values so the children don’t reach a horizontal state ~45-60 degrees is plenty.

Thanks again for your help, I learned a lot and I ended up using bits and pieces for other things too, like a few positions and scales.

• ### Eduardo Oliveira

March 8, 2016 at 10:44 am

yeah man, keep experimenting! that’s how i lost my fear of expressions :).

an unnecessary idea: you could use the parent’s “y” velocity and use it as a modifier, after the main expression gets calculated, you add/remove a bit of rotation depending on the vertical speed (positive or negative). i have something on my mind already but it would be a cool exercise to fry your brain a little and learn more =)

if you do actually decide do to it, and have any problems, ill be here to help.

All the best!

• ### Jake Dickey

April 25, 2016 at 10:59 pm

Ack… Several hours spent trying to figure this out so far, but it’s time to ask: How do I make this work!?

I’ve been applying this expression to the position field, with an error message popping up saying “expression result must be of dimension 2, not 1.”

You said something about this code being more for “x” motion, such as for dangling objects, so I tried separating the x,y dimensions of the parent and child objects involved, but I’m not getting any kind of desirable results. There’s not error messages, but the child layer isn’t bouncing at all. It’s just nudging the landing position of the layer.

Anyway, I’m moderately used to using basic expressions, but I’m feeling really dumb for not being able to figure this out. Can you explain exactly where I should be trying to apply this expression for it to work properly?

Do you have any ideas for a more general/universal “parental inertial bounce” expression that can be used directly on the “position”?

Viewing 1 - 10 of 29 posts