Creative COW ACCOUNT & SETTINGS :: SPONSORS :: ABOUT US :: CONTACT US
LIBRARY: TutorialsVideo TutorialsReviewsInterviewsEditorialsFeaturesBusinessAuthorsRSS FeedTraining DVDs

Swinging A Realistic Chain

COW Library : Trent Armstrong : Swinging A Realistic Chain
Swinging A Realistic Chain
Creative COW After Effects Expressions Tutorial




Article Focus:
Creative COW member Trent Armstrong shows you expression features that apply all the way from After Effects 5 to today. He combines his experience as "an average expressions user" with tips and shortcuts for many core features that every AE user will be able to start using today.

trent armstrong

Trent Armstrong
Allen, TX
©Trent Armstrong and CreativeCOW.net

 

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.

 

INSTRUCTIONS
Step 1 - Start by creating a new project and saving it.  I'm calling mine "Swinging Chain."

 

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
Step1
- (Actual Stuff) Select the PreComps folder and create a new Comp (HOTKEY = cmd+n on Mac, ctl+n on Windows).

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
Position - 50, 0

Your comp window should look like this:

 

SETTING UP THE CHAIN BASE
Now that the Link is built, we need to set up the chain. The next few steps will involove expressions, but we should be able to keep it pretty painless.

Step 1 - Select the " FINAL" folder in the project window and create a new composition named "Chain Swing". It should be at least 640x480, square pixels, but I'm creating a 720p comp. 1280x720, square pixels.

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
• Swing Speed - 15
• Time Decay - 1.5
• Link Rotation - 1.01
• Link Size - 75

 

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
Position X=640, Y=0
Scale X=20, Y=20

It's not very exciting yet, but you should see something that resembles this:

 

EXTENDING THE CHAIN
This composition called "Chain Swing" is meant to be dropped into another composition as a complete object so the "Static Link" will always stay where it is and the subsequent links will be positioned relative to that starting point.

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:

EXPRESSION
x = 50;
y = 97;
[x,y]

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.

EXPRESSION
i = index - 1;
linkRotation = thisComp.layer("Effect Controls").effect("Link Rotation")("Slider");
thisComp.layer(i).rotation * linkRotation

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.

MORE CONTROL
For further control we have the ability to change the size of the Links. Part of the process is already in place. We just need to hook up the expressions.

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.

EXPRESSION
x = comp("Chain Swing").layer("Effect Controls").effect("Link Size")("Slider");
[x, x]

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.

EXPRESSION
x = comp("Chain Swing").layer("Effect Controls").effect("Link Size")("Slider");
y = 90;
[x, y]

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:

EXPRESSION
amplitude = thisComp.layer("Effect Controls").effect("Swing Amplitude")("Slider");
decay = thisComp.layer("Effect Controls").effect("Time Decay")("Slider");
swingSpeed = thisComp.layer("Effect Controls").effect("Swing Speed")("Slider");

amplitude * Math.sin(swingSpeed * time)/Math.exp(time * decay)

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.

"Decay" is how quickly the chain gives in to our artificial gravity. You can decrease the swing time by increasing the "Time Decay" slider.

"Swing Speed" can be thought to refer to the mass of the individual links. In the real world a large string of links will have a nice full swing but swing slower than a string of smaller links. To get that kind of result, set "Swing Speed" to 8 and "Time Decay" to .5.

The math at the end of the expression takes all those variables and applies them with an exponential decay to have the chain appear to be reacting to actual gravity and wind resistance.


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.

 

 

 

  Digg it Digg itAdd Comment
Comments

Swinging A Realistic Chain
Thanks for you help, i'm working on a project for schoool and it would be very helpful to what i'm trying to make. right now i'm just key framing all of the animation by hand and its taking forever!
by Mary Twohig on Jan 14, 2008
Swinging A Realistic Chain
I'm not sure how you would go about it. It seems like each link would essentially need two anchor points (one at each end) and the math would be tricky. Not sure you can get there from here. Nice idea though!

Dan
by Dan Ebberts on Jan 11, 2008
Swinging A Realistic Chain
Good question! I'm going to put the question to Dan Ebberts to see if he has any thoughts.

It's good to have not just Dan but a forum full of top notch Expressioneers!

Trent
by Trent Armstrong on Jan 11, 2008
Swinging A Realistic Chain
is there a way to pin the chain at both ends? so you can animate the ends and then have that nice procedural swing in the middle.
by Mary Twohig on Jan 11, 2008
Swinging A Realistic Chain
Here is the rest of that tutorial! Many apologies for leaving this step off. That wasn't very nice of me!

Step 5: 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:

Expression:
amplitude = thisComp.layer("Effect Controls").effect("Swing Amplitude")("Slider");
decay = thisComp.layer("Effect Controls").effect("Time Decay")("Slider");
swingSpeed = thisComp.layer("Effect Controls").effect("Swing Speed")("Slider");

amplitude * Math.sin(swingSpeed * time)/Math.exp(time * decay)

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.

"Decay" is how quickly the chain gives in to our artificial gravity. You can decrease the swing time by increasing the "Time Decay" slider.

"Swing Speed" can be thought to refer to the mass of the individual links. In the real world a large string of links will have a nice full swing but swing slower than a string of smaller links. To get that kind of result, set "Swing Speed" to 8 and "Time Decay" to .5.

The math at the end of the expression takes all those variables and applies them with an exponential decay to have the chain appear to be reacting to actual gravity and wind resistance.
by pxlguy on Nov 16, 2007
Swinging A Realistic Chain
Carl added a nice twist to the concept there. It kind of looks like holding the chain in your fingers and giving it a shake.

The original idea was for the chain to be held up by the bottom and then dropped. You can see the application at the end of our "SMART" video when the bulb is created out of thin air.
http://www.ignitermedia.com/products/iv/singles/569/Smart

by pxlguy on Nov 12, 2007
Swinging A Realistic Chain
Look s abit rigid at the moment. I tried a version with a delay set on each link:

movie:
http://www.mediafire.com/?dnuew22vm00

aep:
http://www.mediafire.com/?d1ju9xttcuv

by Carl__F on Nov 9, 2007
Swinging A Realistic Chain
this doesn't produce the exact same effect as the movie he provided, but it's at least a step towards it:
add the following expression to the Static Link Rotation

startSwing = thisComp.layer("Effect Controls").effect("Swing Amplitude")("Slider");
timeDecay = thisComp.layer("Effect Controls").effect("Time Decay")("Slider");
thisComp.layer("Static Link").rotation = (startSwing - time*timeDecay)*(Math.cos(time*1.1));

hope that works.
by halexmorph on Nov 7, 2007
cow starcow starcow star
Swinging A Realistic Chain
Missing informations, cannot complete your tutorial, please help :)
by Marky Mark on Nov 7, 2007
Swinging A Realistic Chain
I think he left out a few steps. If you play around with the numbers the expressions all seem to work fine, but the rotation never changes. I'm assuming there was some expression/step to do this that was forgotten
by halexmorph on Nov 4, 2007
cow star
Swinging A Realistic Chain
I followed this tutorial to the T and it still doesn't work at all, does anybody have any thoughts as to why not?
by mikekameron on Oct 23, 2007


Related Articles / Tutorials:
AE Quick Tips #4: Copy Expression OnlyCreating Advanced Glitter using Expressions with Trapcode ParticularCreating a Hologram Look in After EffectsUsing Brainstorm in AE CS3Light Writing,Part 2


Recent Articles / Tutorials:
Stack Tracks: Layered Digital MusicHP XW4600 WorkstationApple Final Cut Server: A Creative Cow Real-time ReportTornado Text, part 1The Sony PMW-EX1 XDCAM EX Camera: A Closer Look
MORE
G-Tech
Training DVDs

FORUMSLIBRARYPODCASTSBLOGSMAGAZINESERVICESNEWSLETTERSNEWSSTOREEVENTS

© CreativeCOW.net All rights are reserved.

[Top]