I decided to continue this **After Effects** **expression** sharing series. Because I feel my first article was welcomed by some animators. I’m not sure how many samples I can share but I’ll share my code as much as possible.

Anyway, I share basic one again, yes it’s **Pendulum**. I think Pendulum movement is one of simplest but most useful thing. With this code, you can add **omni-directional** pendulum movement. If you want to animate like below, please check my code and/or download AEP.

I know you already know the simple pendulum expression like below. By the way, I use position property as a sample case.

freq = 1;
amp = 50;
value + [0, amp * Math.sin(freq * time * 2 * Math.PI)];

And below is my sample code. Also, you can download sample AEP on my Gumroad.

**[Omni Directional Pendulum]**

freq = 1;
amp = 50;
waveAngle = 40; //You can adjust the pendulum angle by changing this value.
wave = amp * Math.sin(freq * time * 2 * Math.PI);
value + [-wave * Math.sin(degreesToRadians(waveAngle)), wave * Math.cos(degreesToRadians(waveAngle))]

In the next sample, the expression calculates the pendulum angle which is vertical to the direction of movement.

**[Advanced version]**

freq = 4;
amp = 20;
waveAngle = radiansToDegrees(Math.atan2(velocity[1], velocity[0])); // calculating the angle with position property's velocity.
wave = amp * Math.sin(freq * time * 2 * Math.PI);
value + [-wave * Math.sin(degreesToRadians(waveAngle)), wave * Math.cos(degreesToRadians(waveAngle))];

Do you enjoy this article? This code might not be useful for every situation. But I hope it helps you out even just a bit to learn AE expressions.

### Like this:

Like Loading...

*Related*