After Effects Tutorials Series 3: Solving Rigging Problems with Masks, Pins, & Expressions

Creating a retractable robot arm

You’ll find information about this tutorial series on the directory page.

In this video I’ll show you how I constructed Zero-Forty-Two’s arms as well as how the retraction combined with bending of the arm was achieved. By using the index expression I’ll also show you how the entire retracting and extending movement was achieved by copying a single expression 16 times, saving me from having to write 16 separate expressions.

I have provided a short summary of the code used in the robot arm below the video.

For more about the index expression check out the glossary click this link.

Please note: In the video I explain in detail how the expression that controls the arm segments was constructed and what each line of the code means. The information below is provided as a reference for people who have already watched the video and understand how the code was designed and how it works.

The beauty of the index expression is that it allows you to create a single expression for multiple layers even when each layer demands a different result. The expression for all 16 layers of Zero-Fotry-Two’s arm segments looks like this (I prefer my code to be verbose for clarity):

  1. //right arm universal code 04-23-2017
  2. //SX is start x; FX is finish x; SV is slider value (0-50); Y is set at original value
  3. SV=Place the location of your control slider here using the pick whip.;
  4. Y=value[1];
  5. SX=150.2+(26*(index-4));
  6. FX=476.2+(3*(index-4));
  7. X=linear (SV,0,50,SX,FX);
  8. [X,Y]

Note: The above script is based on setting the control slider range to 0 through 50. All of the arm segments and the claw (hand) are placed in an arm pre-composition. Left – right directions below are from your perspective, not the puppet’s perspective.

Lines 1 & 2:

Information lines. After Effects ignores lines preceded by double slashes //

Line 3:

Assigns the variable SV to the value of the slider you want to use to control the arm retraction and extension.

Line 4:

Assigns the current value of the y position property to the variable Y. The arm does not move in the vertical axis within the arm pre-composition and so it remains constant. While I could have chosen to separate the (x, y) values of the position property by right clicking on the property in the timeline and selecting the separate values option from the drop down menu, I would have had to to that manually for all 16 arm layers. Using the value expression achieves the goal by typing one short line of code.

Line 5:

The variable SX is assigned the value of 150.2 + (26 * (index – 4)).

Remember that each arm segment, when extended, is 26 pixels apart from the previous (to the left) arm segment. This means that if the x position of the end arm segment was 0, than the position of the second one would be (0 + 26) pixels from the first. The next one would be (0 + 26 + 26), or (0 + (26 * 2)), pixels from the first. The next would be (0 + (26 * 3) pixels away from the first, and so on.

Instead of 0, the x position of the end arm segment is 150.2.

The expression index returns the layer number. Four is subtracted from index because the arm segments start on layer 4. This creates the following pattern in the 16 arm segment layers:

SX in layer 4:

150.2 + (26 * (index – 4))
150.2 + (26 * (4 – 4))
150.2 + (26 * 0 )
150.2 + 0

SX in layer 5:

150.2 + (26 * (index – 4))
150.2 + (26 * (5 – 4))
150.2 + (26 * 1 )
150.2 + 26

SX in layer 6:

150.2 + (26 * (index – 4))
150.2 + (26 * (6 – 4))
150.2 + (26 * 2 )
150.2 + 52

And so on…, placing each arm segment 26 pixels from the one to the left of it.

Line 6:

The variable FX is assigned the value of 476.2 + (3 * (index – 4).

When fully contracted, the end arm segment has a position of 476.2. All the other segments are 3 pixels distance from the one on the left. The expression follows the same logic as line 5 using the contracted position numbers.

Line 6:

The variable X is assigned the value of linear(SV,O,50,SX,FX), where:

SV is the current slider value;

0 is the minimum value the slider can return;

50 is the maximum value the slider can return;

SX is the value of the starting x position; this value depends on the current layer index number;

FX is the value of the final x position; this value depends on the current layer index number.

Linear will return a single value which depends on the value of SV as mapped (interpolated) to the set of numbers SX through FX. For an explanation of the linear() expression click this link.

Line 7:

The (x, y) position of the layer will be the values of the X and Y variables.

*Don Q Media  and Jared Mark Graham have no affiliation with Adobe Systems Inc.