Adobe After Effects Rotation Expression + How To Use It

In After Effects, the rotation expression automates and controls layer rotation, eliminating the need for manual keyframing. By leveraging this expression, you can create dynamic animations, adjust rotation speed, and even link rotation to layer positions for more complex effects.

December 10, 2024
Adobe After Effects Rotation Expression + How To Use It

Rotation Expression For Adobe After Effects

What Does This JavaScript Expression Do?

The rotation expression in After Effects is a tool that allows you to automate the rotation of layers. Instead of manually setting keyframes to make a layer rotate, you can use expressions to automate and control the rotation behavior. Here's what the rotation expression does:

  • Automated Rotation: The rotation expression can make a layer rotate automatically without the need for keyframes. This is particularly useful when you want a continuous rotation or a rotation that responds to other parameters.
  • Control Rotation Speed: By using the time expression, such as "time" or "time*300", you can control how fast the layer rotates. The value you multiply with "time" determines the speed. The higher the value, the faster the rotation.
  • Rotation Based on Position: The rotation expression can also be used to rotate a layer based on its position or the position of another layer. This is useful in scenarios like animating a car wheel. As the car (layer) moves, the wheel (another layer) rotates in response to the car's position.
  • Reduce Manual Keyframing: One of the primary benefits of using the rotation expression is to reduce the need for manual keyframing. Instead of setting multiple keyframes to define a rotation, you can use a single expression to achieve the desired effect.

Basic Rotation

time

Use this expression for a basic rotation.

Fast Rotation

time*300

Use this expression to increase the rotation speed.

Rotation Based on Position

thisLayer.transform.position[0] *.8

Rotate a layer based on its position.

How To Use It

Accessing the Rotation Expression:

  1. To access the rotation expressions in After Effects, you'll want to click on the triangular menu button located on the left side of your layer.
  2. From there, open the transform effects. Within these effects, you'll find the rotation property.
  3. If you're someone who prefers keyboard shortcuts, simply select your layer and press 'R'. This action will bring up the rotation property automatically.

Starting with Expressions:

  1. Navigate to the rotation property.
  2. To the right of the word "rotation", there's a stopwatch icon. Hold ALT and click on this icon.
  3. A space will appear to the bottom right of your layer. This is where you'll be placing your expressions and coding in After Effects.

One of the most useful ways to make your animation life easier is to have layers animate autonomously. By using an expression, you can have a layer rotate by itself. Moreover, you can dictate the speed of this rotation. For instance, using the time expression, you can make a layer spin. The formula "time" will make your layer rotate. If you find the rotation too slow, you can increase the speed by multiplying time by a value, for example, "time*300". The higher the number you multiply time by, the faster the object will rotate.

Another fascinating use of the rotation expression is to rotate a layer based on its position. Imagine needing to animate a car's wheel turning. Instead of manually keyframing the wheel's rotation, you can use the rotation expression to drive the wheel's rotation based on the car's position change. An example expression for this would be "thisLayer.transform.position[0] *.8". This expression references the position of the layer you're rotating. If you want the rotation to follow another layer, you can use the expression pick-whip to select the layer's position you wish to reference.

Examples & Techniques For Rotation Expressions

Maintaining consistent rotation behavior or adding dynamic rotation effects in Adobe After Effects often involves using expressions. Here's a detailed look at examples and techniques to use rotation expressions effectively.

1. Basic Rotation Expression

To rotate an object at a constant speed:

  1. Select your layer.
  2. Alt-click (Option-click on Mac) the stopwatch next to the Rotation property.
  3. Enter the following expression:
    1. time * 30
  4. This rotates the object at 30 degrees per second.

2. Oscillating Rotation (Swing Effect)

To create a back-and-forth swinging motion:

  1. Add this expression to the Rotation property:
  2. Math.sin(time * 2) * 30
    • time * 2 controls the speed of the oscillation.
    • 30 controls the maximum rotation angle.

3. Looping Rotation

To create a continuous looping rotation:

  1. Use this expression:
  2. loopOut(\"cycle\")
  3. This works when you keyframe the rotation at specific points and want it to loop endlessly.

Alternatively, for a custom looping speed without keyframes:

time % 5 * 72

This rotates the layer in a loop, resetting every 5 seconds (72 degrees per second).

4. Rotation Based on Layer Index

To rotate layers uniquely based on their index (great for cascading effects):

  1. Add this expression:
  2. index * 15 + time * 20
    • index * 15 offsets each layer's starting rotation by 15 degrees multiplied by its index.
    • time * 20 applies a global rotation of 20 degrees per second.

5. Randomized Rotation

To add random rotation behavior:

  1. Use this expression:
  2. wiggle(1, 45)
    • The first parameter (1) sets the frequency of the wiggle (1 change per second).
    • The second parameter (45) determines the range of the random rotation (-45 to 45 degrees).

6. Rotation Controlled by Audio

To sync rotation to an audio amplitude layer:

  1. Add an audio file and use Keyframe Assistant > Convert Audio to Keyframes.
  2. Link the rotation to the audio keyframes with this expression:
  3. thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider") * 2
  4. This rotates the layer based on the audio amplitude.

7. Rotation with Time Deceleration

To gradually slow down rotation:

  1. Use this expression:
  2. Math.max(0, 360 - time * 60)
  3. This starts at 360 degrees and decreases over time until it stops at 0 degrees.

Practical Examples

Example 1: Smooth Rotating Fan Blade

  • Use the basic expression:
  • time * 120
  • This spins the fan blades at a consistent speed of 120 degrees per second.

Example 2: Wobbling Clock Pendulum

  • Add the oscillating expression:
  • Math.sin(time * 3) * 15
  • This creates a swinging pendulum effect with a 15-degree maximum swing.

Example 3: Cascading Rotating Gears

  • Use the layer index-based expression:
  • index * 10 + time * 50
  • Each gear rotates at 50 degrees per second but starts at a unique angle based on its layer index.

Advanced Tips for Rotation Expressions

Combine Expressions for Complex Animations

You can blend multiple expressions to create advanced effects. For example, a rotating pendulum that also wobbles slightly:

Math.sin(time * 2) * 30 + wiggle(1, 5)

Link Rotation to Other Properties

  • Synchronize rotation with scale or opacity:
  • thisComp.layer("Control Layer").transform.scale[0] * 0.5
  • This links rotation to the X-scale of a control layer.

Control Rotation with Sliders

  1. Add a null object and apply a Slider Control effect.
  2. Link the rotation to the slider:
  3. effect("Slider Control")("Slider")
  4. Adjust the slider to control rotation dynamically.