ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Simple layer expression to stagger animation

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jason BrownSimple layer expression to stagger animation
by on Oct 19, 2010 at 7:56:28 pm

I have 4 layers, expression pointed to the keyframed X rotation of a Null. I want them to follow the X rotation to flip up, but I'd like them to ripple...so I need to have them follow the rotation of the Null, with a seperation of a period of time.

Current expression:

thisComp.layer("Rotate up products").transform.xRotation

I have VERY LITTLE experience with expressions, but I need to do this several times, so I'd like to reuse this function.


Return to posts index

Walter SoykaRe: Simple layer expression to stagger animation
by on Oct 19, 2010 at 8:18:26 pm

[Jason Brown] "I have 4 layers, expression pointed to the keyframed X rotation of a Null. I want them to follow the X rotation to flip up, but I'd like them to ripple...so I need to have them follow the rotation of the Null, with a seperation of a period of time."

Check out Dan Ebberts's Motion Trails for an example and explanation of how to do this with valueAtTime.

Walter Soyka
Principal & Designer at Keen Live
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
RenderBreak Blog - What I'm thinking when my workstation's thinking
Creative Cow Forum Host: Live & Stage Events


Return to posts index

Roland R. KahlenbergRe: Simple layer expression to stagger animation
by on Oct 20, 2010 at 3:48:52 am

AccK! I know this one Walter. ;-)

The following should do the trick. Just ensure that the entire scrpt is on a single line when you paste it in AE.
// script to create follower attributes for xRotation
//start script
thisComp.layer("Null 1").transform.xRotation.valueAtTime(time-(index*.1))
//end script

Instead of a "-", you could also have a "+" if you wanted a follower layer to lead the pack, so to speak. Index is a direct reference to each layer's layer numbering in the Timeline.

For a slightly more complex rendition but with more control and an easier path towards experimentation to allow you to quickly find just the right multiplier (index*.1, in the example here), try the following.

1) Apply a Slider Expression Control to the Null Layer.
2) Rename the Slider Expression Control to Multiplier
3) Apply the following script to the other layers -
// start script
NullRotator = thisComp.layer("Null 1").transform.xRotation;
Multiplier = thisComp.layer("Null 1").effect("Multiplier")("Slider");
NullRotator.valueAtTime(time-(index*Multiplier))
// end of script

You can even keyframe the Multiplier expression control.

TIP - You can apply the script to a layer, then select the property with the Script applied and select Edit>Copy Expression Only. Then simply select all the other layers and Paste (CTRL+V). THe Copy Expression menu command only copies the Expression selected. The benefit of this is that you can then select layers without having to explicitly initiating Expressions for other layers that you want to apply the Expression onto.

HTH

AE Training in South East Asia. AE templates for sale and rental. Click here for more


Return to posts index


Jason BrownRe: Simple layer expression to stagger animation
by on Oct 20, 2010 at 4:48:58 am

WAY over my head...but I was able to make your first suggestion work...I appreciate the reference to Dan's materials. I've watched many tutorials, and most of that seems to be out of my mental capacity!

I'd like to understand (from a very basic understanding) how this does what it does...can you break down the parts?


thisComp.layer("Null 1").transform.xRotation.valueAtTime(time-(index*.1))

I've got everything to .valueAtTime. I don't fully understand how index relates to layer number and why the multiplication of .1? I've tweaked it and can't seem to make rhyme or reason to the numbers.

Thanks SO MUCH btw for your help! This is why I love the cow...great dialogue and awesome ideas!

-Jason


Return to posts index

Roland R. KahlenbergRe: Simple layer expression to stagger animation
by on Oct 20, 2010 at 6:49:41 am

This is a good start to understanding AE Expressions. Just take note that a few of the Expression methods have changed. In JJ Gifford's examples (version 5 I think), for example, this_comp.layer("Solid 1").opacity was how we used to point to another layer's Opacity. With version 7 onwards (I think), it is now, thisComp.layer("Solid 1").transform.opacity.

The only change is in the underscore used previously and the capitalization of the word Comp.

Those pages will give you a good foundation.

With respect to the specific Expression I provided, take note that the entire premise for Expressions is to point to attributes across compositions, layers and their parameters. Using Math and logical operators allows us to affect these assets and their properties. To affect these assets, we need to be able to point to them.

Using composition, layer and property names is one way to point to these assets and they do serve our intent most of the time. However they lack mathematically specification. IOW, there is no way of affecting the layer above thisComp.layer("John's Car") without using the index object.

For example, if I typed, thisComp.layer("John's Car")-1, I would be prompted with an error-induced dialog.

index is an object or a global variable in AE Expressions. These are reserved terms in AE. Specifically, index is used to easily point to a layer within the Timeline. index does this be referencing layers based on their hierarchy in the Timeline. Each layer is AE is given an index. This index is denoted as a column with a column heading with the # sign.

What may confuse you is that a layer's index may change as you add, remove or shift a layer's vertical position within the Timeline structure. While this is a shortcoming, more often than not, using the index object work brilliantly.

In the example provided, I used (index-.1). Take note that Index is strictly a number. Different layers will always have a different index number. Using (index-.1) allows for a different value for each layer where this Expression exists. All you have to do is to mentally replace index with integers from 1-4 and you'll see that the result is different each time.

This difference is what allows for each layer to rotate differently. But the difference in this case isn't in terms of absolute values but in terms of time. And this is due to us using the valueAtTime method which points to a layer's value at a particular point in time.

I used .1 cos I like the number 1. I could have used 7 or 10 which are also my other favorite numbers. I could have just index on its own without using (index-.1).

But I wanted to use a number for index to operate on because it leads me to my next example, the second script that I provided. In the second script, (index-Multiplier), index affects a Slider Expression Control, named Multiplier. Since all the layers point to the same Slider Expression Control, by changing the slider value, the affected Expression on each layer will update accordingly.

This paradigm of using Expression sliders provides absolute advantage in that I can test for different values until I get the exact look I want. In your case, without testing the script out, you can't really tell how long the delay should be before subsequent layers start rotating.

Using the script in example 1, you would have to go through a number of tries before you found a workable number for (valueAtTime(time-number). IOW, you may know that you need to use the valueAtTime Expression method but you would still be messing about until you got the number just right so that it gave you the result you wanted.

Just imagine the number of times you would have to change the number, then copy and paste it across the other layers then RAM Preview. And then possibly go through the process again and again until you were happy with the result. IOW, lots of copying and pasting.

Spend some time on the URL and if you persevere you should be able to grasp Expressions and be productive with it.

And in the future, you would want to use the COW's AE Expressions Forum.

HTH
RoRK

AE Training in South East Asia. AE templates for sale and rental. Click here for more


Return to posts index

Jason BrownRe: Simple layer expression to stagger animation
by on Oct 20, 2010 at 4:22:40 pm

[Roland R. Kahlenberg] "This is a good start to understanding AE Expressions. "

I've read through this YEARS ago! :) I remember reading "When not to use expressions - Whenever you can avoid them" haha...

I just thought this need was a good small purpose that would be a good expression use.

I've read through your response 3 times and I'm still processing...



[Roland R. Kahlenberg] "a layer's index may change as you add, remove or shift a layer's vertical position within the Timeline structure."

So can you call a layer out based on it's "index" -- like replace the code:
(index-.1)

with

(#1-.1)


or is index based on the relative position of the layer it's "parented to" by the expression?

-Jason


Return to posts index


Roland R. KahlenbergRe: Simple layer expression to stagger animation
by on Oct 20, 2010 at 5:15:13 pm

[Jason Brown] "So can you call a layer out based on it's "index" -- like replace the code:
(index-.1)
with
(#1-.1)"


No can do! #1 is not an object specified by the Expression language. However, index is. Thus, index-1 or index+1 or index-2 etc are appropriate forms for use.

# is just the title of the column heading for index in your Timeline stack. It is not part of the Expression language.

Index has to be used in conjunction with the layer object. To reference a layer using index, the syntax would be like this -
thisComp.layer(index-2).transform.xRotation. This script will refer to the xRotation of a layer, two layers above the layer which has this Expression.

HTH
RoRK

AE Training in South East Asia. AE templates for sale and rental. Click here for more


Return to posts index

Jason BrownRe: Simple layer expression to stagger animation
by on Oct 21, 2010 at 6:46:12 pm

OK!

So index is like saying "this layer"

and then subtract or add to move up or down the layer stack?

So in your original expression, you made a time reference to index*.1

Did this effectively take a fraction of the placement of the layer below?

Thanks so much...it's beginning to make more sense to me!

-Jason


Return to posts index

Roland R. KahlenbergRe: Simple layer expression to stagger animation
by on Oct 21, 2010 at 8:10:52 pm

[Jason Brown] "So index is like saying "this layer""

YUP! And "index-1" is the layer above. And "index+2" is the layer two rungs below.

[Jason Brown] "So in your original expression, you made a time reference to index*.1" Did this effectively take a fraction of the placement of the layer below?

AAccCCCKK!!! NO! YOu can't take a fraction of a layer. It doesn't make sense. What happened in the script was to take a fraction of time.

Here's the script again.
thisComp.layer("Null 1").transform.xRotation.valueAtTime(time-(index*.1))

Let's forget about the using index for now. We would then have the script as such -
thisComp.layer("Null 1").transform.xRotation.valueAtTime(time)


Think of time as the Timeline Indicator. Let's create a Null layer and name it Null 1 and a solid and give it a name, follower1.
Animate the xRotation of Null 1 and paste the above script into the xRotation property of follower1.

If you tried this script out, both layers will rotate at the same time. The referenced layer, layer Null 1 will rotate and the 'follow' layer with the script, will rotate at the same time.

To offset the time that the 'follower layer' rotates, we need to apply a math operator. The minus sign does the job easily here. Take note that (time-.1) means the follower layer starts +.1 from the referenced layer. Therefore, if we have written (time-1), then our follower layer will start one second AFTER the referenced layer started and not before.

So, to have the follower layer delayed, the script would be -
thisComp.layer("Null 1").transform.xRotation.valueAtTime(time-.1)
. .1 is used arbitrarily. It could be any number. Chances are you won't be sure what his number is until you've tested it out and the results are pleasing to your eyes.

Now what it you have four follower layers instead of just one? In this scenario, if you used the same script for all the follower layers, they would all be offset from the referenced layer at exactly the same time. IOW, they would all rotate as a group. BUT, you want want the follower layers to start one after the other, with a slight delay before each follower layer starts.

If you didn't use the index object, you would type -
thisComp.layer("Null 1").transform.xRotation.valueAtTime(time-.1)

for the first follower layer and
thisComp.layer("Null 1").transform.xRotation.valueAtTime(time-.2)
for the second layer etc etc etc.

Therefore, a slightly different script would be required. Now what happens if you weren't happy with the delay and perhaps you wanted a longer delay before each follower layer starts? Well, you would have to go into each layer's Expression to change the their respective time offset numbers.

Obviously it's going to be a hassle and you may be put off by using Expressions cos copying and pasting keyframes and staggering the keyframes might actually be more productive.

So, how do we preclude having to jump into each layer's Expression everytime we wanted to adjust the time offset? This is where the index comes in and provides an elegant solution.

Since we now know that index is another way to name a layer and index is denoted by integers, we can use its mathematical feature to commit index to math operators.

Back to the original script -
thisComp.layer("Null 1").transform.xRotation.valueAtTime(time-(index*.1))
If we used this script on all the four follower layers, the actual math that goes on would be such -
1) for layer follower1 which is at the top of the Timeline - valueAtTime(time-(index*.1)) will be calculated as
valueAtTime(time-(1*.1)), where index is replaced by the layer's actual indexed number, which is it's position in the Timeline stack.

2) for layer follower2 which is second from the top of the Timeline - valueAtTime(time-(index*.1)) will be calculated as
valueAtTime(time-(2*.1))

and for the third layer from the top,
3) for layer follower1 which is at the top of the Timeline - valueAtTime(time-(index*.1)) will be calculated as
valueAtTime(time-(3*.1))

WIth this method, you can use the same script across all the four layers. If you wanted to change the operand, you only need to change it once and then copy and paste it onto the other three layers.

For even more oomph! YOu can link the operand (.1) to an Expression slider. The benefit of doing this is that by simply changing the slider value, you wil be updating all the Expressions on all the layers without having to perform the copy-paste routines.

Additionally, by linking to an Expression Control slider, you can animate the operand to achieve interesting effects.

I suggest that you try the scripts out across different parameters. With more hands-on and trial and the occasional error, you should be able to have a better grasp. All this theory isn't any good if you're not going to test them out.

HTH
RoRK

AE Training in South East Asia. AE templates for sale and rental. Click here for more


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]