|Swinging A Realistic Chain|
There have recently been several tutorials listed here on creativecow.net that have started teaching the basics of expressions. I've also seen some really advanced tutorials like the manual lens flare with some really advanced expressions. We'll I'm an average expressions user that is trying to figure out how to build expressions to work like plugins with easy controls that do powerful things.
In this example I'm going to set up a chain that starts swinging and then appears to be effected by gravity until it comes to a stop. At the end of the tute we'll be able to control the amplitude of the swing, the speed of the swing, and the gravity or how quickly the chain stops swinging. And with many new tutorials coming out that are made specifically for AE CS3, I thought it might be fun to do something that can work in versions of AE at least back to version 5.0.
Step 2 - Create two folders named " FINAL" and "PreComps". There is a space in front of " FINAL" so it rises to the top of the list.
NOTE: We're not creating a lot of comps in this project, as a good organizational practice, I always create the same few folders. I would normally add an "Assets" folder or "Movies" and "Stills" depending on the needs of the project. This way when I open it back up or give it to someone else, it is easy to decipher.
CREATING THE LINK
Name the comp "Chain Link" and make it 100px wide and 100px tall.
Step 2 - Create a new solid (HOTKEY = cmd+y on Mac, ctl+y on Windows). Name the solid "Bead", click the button for make "Make Comp Size", change the color to a solid Black, and click OK.
Step 3 - Duplicate the Bead solid, select the top layer, and select the circular mask tool from the tool palette.
Now, double-click on the circular mask tool to apply a circular mask to the full limit of the solid on Layer 1.
Step 4 - Open the Position and Anchor Point layer transform properties for the "Bead" layer. (HOTKEYS = P and A) Click the second number, the Y value, for Position and set it to 100. Then Click the second number for the AnchorPoint (Y value) and set it to 100. This keps the layer in place and puts the Anchor Point at the edge of the layer and the comp. It should look like this:
Step 5 - Select Layer 2, name it "Chain", and unlink the scale properties. Set X to 70 and set Y to 90. Then reveal the Anchor Point and Position properties.
Set them to the following values:
Anchor Point - 50, 0
Your comp window should look like this:
SETTING UP THE CHAIN BASE
Step 2 - Create a Null Object named "Effect Controls." You can create a Null with Layer> New> Null Object. A NULL is a blank layer that can be used to aid in controlling a number of different aspects of a composition. In this example I'm only using it as a place to put my effect slider controls.
Step 3 - Select the "Effect Controls" NULL and Select Effect> Expressions Controls> Slider Control from the Effect menu. Select the newly applied slider and hit RETURN to change the name of the Slider Control to "Swing Amplitude."
Step 4 - Duplicate the Slider Control enough times to have the following individual controls and set each to the corresponding value:
• Swing Amplitude (already created) - 13
Step 4 - Drag the "Chain Link" comp into the "Chain Swing" comp. Select the "Chain Link" layer, hit RETURN and name it "Static Link" then set the following values:
Anchor Point X=50, Y=0
It's not very exciting yet, but you should see something that resembles this:
EXTENDING THE CHAIN
Step 1 - Duplicate the "Static Link" layer, move to the bottom, and rename it to "Link".
Step 2 - Parent the "Link" layer to the "Static Link" with the Pick Whip.
Step 3 - Twirl down the Position property and option+click (alt+click on Windows) the Stop Watch next to Position.
Doing this adds an expression to the Position property. With the Expression Field still selected enter the following text:
Hitting the ENTER key will apply the expression.
This gives the "Link" layer a constant relative position to the "Static Link". Even if the Position property is changed accidentally, this will keep the "Link" locked to the "Static Link".
Step 4 - Create the next link by duplicating the "Link" layer. After Effects will auto name the new layer "Link 2."
Step 5 - Repeat Step 4 for as many layers as you need until your chain is long enough. I created 16 Links to have a good length on the chain and every layer is parented to the layer immediately above it.
As you can see, all the links have spaced themselves correctly using the expression for Position.
This expression takes the Rotation of the previous layer and multiplies it times the value of the Link Rotation slider control. The result is that there is a slight increase in rotation per link as the math moves down the chain.
Step 3 - Select the Rotation property of the "Link" layer and select Edit> Copy Expression Only from the menu bar. Then SHIFT select all of the links from "Link 2" to your last link and Paste the expression by hitting cmd+v on the Mac or ctl+v on Windows. This will apply the rotation expression to each of the selected layers.
Finally, it's time for a RAM Preview. Hit the 0 (zero) key on the number pad and watch the chain swing away. Turning on Motion Blur will add to the realism.
Step 1 - Open the "Chain Link" composition and pull the timeline tab off so you can see the timelines for both "Chain Link" and "Chain Swing."
Step 2 - Twirl down the scale properties for each of the layers in the "Chain Link" comp and reveal the expression field for each.
Step 3 - For the "Bead" layer copy and paste the following expression.
This applies the same value from the "Link Size" slider control to both the X and Y Scale of the "Bead" layer.
Step 4 - Copy and Paste the following expression to the Scale property of "Chain" in the "Chain Link" comp.
This applies the value from the "Link Size" slider control to the X Scale and keeps the Y Scale at 90% for "Chain".
When you adjust the "Link Size" slider control, the links stay together, but the beads get smaller.
Step 5 (Previously Missing) - It's time to make the chain swing! Twirl down the rotation property and opt (or alt) click the stopwatch to reveal the expression entry window. Then copy and paste in the following expression:
In this expression, "amplitude" references the "Amplitude Slider" to give you a range to start with. I like to go big but not too big on this one. "13" is a good number to start with.
I hope this can be a springboard to launch you into trying out more expressions on your own.
Feel free to discuss this tutorial in the Adobe After Effects Expressions Forum at CreativeCOW.net.
Trent Armstrong is a motion graphic designer and video producer for Igniter Media Group in Dallas, TX. He also is the producer and host of The MannersCast, a podcast about everyday manners for everyday folks. More of Trent's work can be seen at www.ignitermedia.com, and The MannersCast is at http://www.mannerscast.com.