How to roll a square in After Effects using Expressions

In our latest project for The Faculty we wanted to roll a square at the start of the animation. This seemed simple when we came up with the idea but animating this in After Effects (AE) was different story. After some research we found the solution at AE Tips and Tricks (aka http://hottek.net), with their clever expression on square wheels - we were able to get the square rolling, so to speak.

The next challenge was to get the square to roll over a triangle. For those who don’t use AE, you’re probably already asleep by now. If you do use AE, read on…

Getting the square to roll over an object

The square needs an expression on it’s anchor (to change it’s position every time it rotates 90°) and its position (to move it along by the width of the square…) – maths innit. You just need to keyframe the rotation, which moves the square nicely across the frame.

Getting the square to roll over the triangle involved parenting the square a Null Object, which is parented to another Null, which is in turn parented to yet another Null (one Null for each angle change). To save me writing a thousand words look at the animated gif below showing the movement of the parented nulls.

Rolling a square in After Effects

As the square reaches the triangle, the nulls rotate, allowing it to “walk” over each angled side

As we haven’t encountered this problem ourselves before, we thought we would share the project so that anyone looking to do the same can apply it to their work. You can download the project here: Rolling Square.aep

Tip: to keep the square rolling on the spot, precompose the square (and nulls, and triangle) make sure you move all attributes into the new composition.

For us the triangle was specific to this animation but this principle could be applied to any shape with straight sides.

If you use a rolling square in your project, or if you’ve found a different way to tackle this problem - please let us know? We’re especially keen to see this working on a circle!

One Comment

Leave a Reply

Find out how we can bring your story to life Contact us today