LIBRARY: Tutorials Reviews Interviews Editorials Features Business Authors RSS Feed

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.

 

 

 

Comments

Re: Swinging A Realistic Chain
by kurt hudson
yea can someone please link me to a tutorial that makes sense and or actually works that is simillar to this? I even re did the whole thing and wasted two whole days on this project and its still not right.. dont they edit these things on creative cow? why would they let a bogus tutorial on here?
Re: Swinging A Realistic Chain
by kurt hudson
This is the most confusing tutorial Ive ever read.. and once I followed it to a T.. it didnt even work.. step 4 goes to step 4 and step 3 goes to step 5 and theres a step missing? does anyone have a replacement tutorial so I can attempt to finish what I was doing? thanks!
Swinging A Realistic Chain
by Mary Twohig
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!
Swinging A Realistic Chain
by Dan Ebberts
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
Swinging A Realistic Chain
by Trent Armstrong
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
Swinging A Realistic Chain
by Mary Twohig
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.
Swinging A Realistic Chain
by pxlguy
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.
Swinging A Realistic Chain
by pxlguy
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

Swinging A Realistic Chain
by Carl__F
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

Swinging A Realistic Chain
by halexmorph
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.
Swinging A Realistic Chain
by Marky Mark
Missing informations, cannot complete your tutorial, please help :)
Swinging A Realistic Chain
by halexmorph
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
Swinging A Realistic Chain
by mikekameron
I followed this tutorial to the T and it still doesn't work at all, does anybody have any thoughts as to why not?


Related Articles / Tutorials:
Adobe After Effects Expressions
Adobe After Effects Expressions 101

Adobe After Effects Expressions 101

Expressions in Adobe After Effects open up a world of possibilities for your visual effects! Expressions can be daunting when you first get into them, though, as you have to essentially write 'code' - and code can be scary. Join After Effects guru Tobias Gleissenberger of Surfaced Studio for the first in a series covering expressions, from the very basics - all the way through to programming the Matrix!

Tutorial
Tobias Gleissenberger
Adobe After Effects Expressions
In The Loop - A Killer Expression

In The Loop - A Killer Expression
  Play Video
A detailed explanation and demonstration of the uses of the loop expression in After Effects. Examining the loopOut(), loopIn(), loopInDuration(), loopOutDuration() commands and their "ping pong", "cycle" and "continue" modes.

Tutorial, Video Tutorial
Matthew Tompkins
Adobe After Effects Expressions
EQ Animation using AE Expressions

EQ Animation using AE Expressions
  Play Video
In this video tutorial Matt Tompkins gives some great tips on how to create and animate a rack of Graphic Equalizer bars using solely expressions in Adobe After Effects.

Tutorial, Video Tutorial
Matthew Tompkins
Adobe After Effects Expressions
Jack of All Trades, Master of Expressions

Jack of All Trades, Master of Expressions
  Play Video
In this video tutorial, Creative Cow contributing editor Eran Stern demonstrates how to create a jumpy and squishy animation using the power of expressions.

Tutorial, Video Tutorial
Eran Stern
Adobe After Effects Expressions
AE Quick Tips #4: Copy Expression Only

AE Quick Tips #4: Copy Expression Only
  Play Video
In this video tutorial, CreativeCow leader Aharon Rabinowitz shows you a menu item for speeding up the process of copying expressions to other layers, without typing or altering the current values.

Tutorial, Video Tutorial
Aharon Rabinowitz
Adobe After Effects Expressions
Animating Text Reflections with ExpressionsAnimating Text Reflections with Expressions

In this tutorial from Creative COW Contributing Editor Trent Armstrong, you'll see how to use Expressions to animate reflected light across text. You can get great results using only ingredients included free with AE, including track mattes and the AE Camera.

Tutorial
Trent Armstrong
Adobe After Effects Expressions
Building and Animating a CG SnakeBuilding and Animating a CG Snake
  Play Video
In this video tutorial from CreativeCOW.net you will learn how to create a dynamic animation based on a chain rig. You will also learn how to animate one layer using keyframes, expressions, or both, and make other layers follow the leading layer. The rest of the tutorial is about texturing and making the final look.

Tutorial, Video Tutorial
Jerzy Drozda Jr
Adobe After Effects Expressions
Using Expressions to Create a Volume MeterUsing Expressions to Create a Volume Meter
  Play Video
In this video tutorial from CreativeCOW.net you will learn how a smart way of creating dynamic a sound reactive Volume Meter using Expressions in After Effects.

Tutorial, Video Tutorial
Jerzy Drozda Jr
Adobe After Effects Expressions
After Effects Expressions Simplified

After Effects Expressions Simplified

In this After Effects tutorial from The Creative COW Magazine, see through the confusion of After Effects Expressions with just a few simple steps.

Tutorial
Andrew Kramer
Adobe After Effects Expressions
A better Grid using expressions

A better Grid using expressions

This tutorial from Mylenium will show you some basic principles when using expressions in After Effects. These include using the pick whip and some simple things you need to think of when referencing elements and converting numerical values.

Tutorial
Mylenium
MORE
© 2016 CreativeCOW.net All Rights Reserved
[TOP]