Create a Gear Rig Using Expressions After Effects

In this lesson we'll be using some expressions that might look a bit complicated, but we promise that you'll get the hang of them. Joey is going to walk you through the whole process of making this gear rig turn using just a bit of math. Don't worry! It's not that bad.

Check out the resources tab for the expressions that Joey used in this lesson if you don't want to type them all in by hand, or if you want to check your work if you're typing them out as you go along.

If you have any questions, click over to the Q&A tab to post them. Other students can answer you, and we'll put our team on the case to try and get you a solution ASAP.

 This expression goes on the Rotation property for each gear. You need to have a controller null called GEAR_CTRL which has the appropriate Slider Controls. Watch the video for explanation.

ctrl=thisComp.layer("GEAR_CTRL").effect("Angle Control")("Angle");
rotOff=effect("Rotation Offset")("Slider");
gearTeeth=effect("Gear Teeth")("Slider");
mainGearTeeth=thisComp.layer("GEAR_CTRL").effect("Main Gear Teeth")("Slider");
cw=effect("Clockwise? ")("Checkbox");
if (cw==1) {
} else {

    00:00:00,118(upbeat music)
    00:00:10,567(bouncing noises)
    00:00:13,393(exciting music)
    00:00:21,525- What's up?
    00:00:22,362Joey here at School of Motion
    00:00:23,714and welcome to day three of 30 days of aftereffects.
    00:00:27,058Today, we're going to talk about one of my favorite topics.
    00:00:30,459It's also one of the dorkiest things
    00:00:32,137that a grown man can talk about.
    00:00:33,908Today, we're gonna take a look at how to animate some gears,
    00:00:36,900because they're kind of a perfect example
    00:00:38,951of something that moves in a mathematical way.
    00:00:42,155And that's something that you don't wanna necessarily
    00:00:44,291have to key frame, especially if you have tons and tons
    00:00:47,533of gears to animate.
    00:00:48,773I'm gonna show you some strategies
    00:00:50,455on how to deal with multiple gears,
    00:00:52,600and also don't forget to sign up for a free student account
    00:00:55,638so you can grab the project files from this lesson
    00:00:58,095and the expressions, as well as assets
    00:00:59,619from any other lesson on the site.
    00:01:01,325Now, let's dive into after effects and get started.
    00:01:04,886So, more expressions for you guys.
    00:01:07,410And those of you who have not watched
    00:01:09,766Intro to After Effects Expressions,
    00:01:12,230you should probably watch that one first
    00:01:14,210because that's gonna let this tutorial
    00:01:16,836make a whole lot more sense for you.
    00:01:18,541I'll link to that in the description for this tutorial.
    00:01:22,376So, what I wanna show you is just another cool way
    00:01:26,629to use expressions,
    00:01:29,095and this is actually gonna get slightly
    00:01:31,657advanced just because when I started
    00:01:34,018building this thing out, you know, as happens so often,
    00:01:37,568you think that this is a simple problem to solve,
    00:01:40,689and it ends up being more complicated than you thought.
    00:01:43,349So, what I wanna show you guys is specifically how to
    00:01:47,588create a system of interlocking gears
    00:01:49,979that really work like real gears.
    00:01:52,367They actually turn correctly and accurately,
    00:01:55,155and they don't intersect
    00:01:58,355and you can control exactly how fast they're turning
    00:02:01,417and they all turn, you know, together.
    00:02:05,179So, let's dive right in and get started here.
    00:02:07,580So, I have, here's what I did.
    00:02:10,698I went into Illustrator
    00:02:13,848and I made four gears, right?
    00:02:15,612So, I made this one and then a little bit smaller,
    00:02:20,533a little bit smaller, and a little bit smaller.
    00:02:24,436And so, let's bring those into a comp
    00:02:26,624and take a look at them.
    00:02:28,325So, I'm just gonna make a new comp.
    00:02:29,922We're gonna call this
    00:02:31,355gear vid.
    00:02:34,881And I am going to just make this
    00:02:38,864a light colored background
    00:02:40,516so we can take a look at it.
    00:02:43,030Alright, so, let's just drag all these in there.
    00:02:45,858One by one.
    00:02:46,691So, you got gear one, gear two, gear three, and gear four.
    00:02:51,805Okay, so, when I started out creating this tutorial,
    00:02:55,939what I thought I would do is just sort of eyeball,
    00:03:01,309the speed of these gears and come up with an expression rig
    00:03:04,954that would let me just kind of keep nudging and adjusting
    00:03:08,068the speed of each gear until it looked right.
    00:03:10,155And it turns out that's actually very tricky
    00:03:12,558because if this gear, let's say this big one,
    00:03:15,844spins around six times
    00:03:19,879then this little one has to spin
    00:03:21,502the exact, correct number of times, otherwise,
    00:03:24,935the teeth are gonna start intersecting with each other
    00:03:28,012and that's not what I wanted.
    00:03:29,115So, I kinda beat my head against my desk for a while
    00:03:33,549and I did some googling and what I found out
    00:03:36,264is that the right way to do this is
    00:03:38,255A, you have to make sure that all of the teeth
    00:03:41,209of these gears are the same size.
    00:03:43,735And what I mean by that is even though this little guy
    00:03:48,175is much smaller than this big guy,
    00:03:50,004if you look at the actual size of the teeth,
    00:03:52,342right, they're the same.
    00:03:54,849So, when I made these in Illustrator,
    00:03:56,227I just made sure to use the exact same size.
    00:04:00,650I can get into exactly how I did that
    00:04:02,713in a different tutorial,
    00:04:03,611if anyone's curious about how I made the gears.
    00:04:06,854So, now that I've got them set up so that they can
    00:04:10,180actually work like real gears, I had to figure out
    00:04:13,532the math involved in making gears work together.
    00:04:17,194And it actually wasn't as complicated as I thought.
    00:04:20,230So, let me start building this rig
    00:04:22,236and then I'll get into the math behind the way gears work.
    00:04:26,045And I hate that there's so much math in my tutorials,
    00:04:28,517but unfortunately, motion design is really
    00:04:31,445full of math in kinda sneaky ways.
    00:04:33,916So, let's start out by making a null,
    00:04:37,545and this is going to be the gear controller, okay?
    00:04:41,377So this is actually gonna have the property on it
    00:04:45,429that I will key frame to rotate these gears.
    00:04:47,774So to do that, I'm gonna add an expression control,
    00:04:51,782specifically an angle control.
    00:04:53,404Alright, and so what I want is to be able to rotate this
    00:04:56,625and have all of the gears rotate correctly.
    00:05:00,533And, you know, there's some other ways you can animate these
    00:05:03,542where they sort of animate themselves, you know,
    00:05:05,705maybe I could use a time expression
    00:05:08,034so that they're constantly rotating.
    00:05:09,861But the good thing about doing it this way
    00:05:12,405is that I can have them kind of jerk when they start,
    00:05:15,994maybe have them overshoot, speed up, slow down,
    00:05:18,936and I can really just control it very nicely with that.
    00:05:21,485So, let's start with this first gear
    00:05:23,908and let's think about what kind of
    00:05:25,387controls you're gonna need for a gear.
    00:05:29,688So, if I'm rotating this, right,
    00:05:31,650and let me just put a key frame on it.
    00:05:33,288Put a key frame here.
    00:05:34,551Move forward three seconds,
    00:05:36,629and why don't we have that just do one rotation, okay?
    00:05:40,612So, that control is just rotating, alright?
    00:05:44,090And it's not driving anything yet.
    00:05:47,779So what I could do is, I could bring up
    00:05:51,900the rotation property of this gear.
    00:05:54,817And bring up this angle control.
    00:05:58,467I can just hit E, bring up the
    00:05:59,900angle control effect and then open that up.
    00:06:03,012So now if I hold option and I click stopwatch on rotation,
    00:06:08,891it opens up an expression for the rotation property
    00:06:11,403on this lair and I can pick whip to that angle control.
    00:06:16,486And so now that gear is rotating
    00:06:18,989based on what this angle control is doing.
    00:06:21,183That's wonderful.
    00:06:22,465So now what about this gear?
    00:06:24,291Well, 'cause one problem is this gear
    00:06:26,661is going to have to spin the opposite direction, okay?
    00:06:30,729So, I know that I'm gonna need the ability
    00:06:33,208to tell the gear which way it's rotating.
    00:06:36,301On top of that, let's just do this real quick
    00:06:40,452so you can see.
    00:06:41,591If I just copy this expression, I can just hit command C,
    00:06:45,910come up to gear two and hit command V, and it will paste it.
    00:06:48,556And obviously, it's not rotating the right way,
    00:06:51,138so I'm gonna double tap U.
    00:06:54,037This is kind of a new thing with the
    00:06:56,966Creative Cloud version of After Effects.
    00:06:58,371If you hit U, it will not bring up any expressions.
    00:07:01,992You have to hit U twice.
    00:07:03,706It'll bring up key frames, just not expressions.
    00:07:06,327If I open this expression and I put a negative symbol
    00:07:10,133in front of it, it will now rotate backwards,
    00:07:12,535but you can see that it looks okay here,
    00:07:15,074but if I scrub forward a few frames,
    00:07:18,445it's gonna start, let me scrub backwards actually.
    00:07:21,022Right there.
    00:07:21,855You can see it's actually intersecting.
    00:07:23,518The gears are, the teeth are intersecting
    00:07:25,710because this gear has less teeth
    00:07:29,284so it has to spin at a different speed.
    00:07:34,023So I'm also gonna need to be able to tell each gear
    00:07:37,291how much faster or slower than the first gear in this chain,
    00:07:44,006you know, how fast or slow it should go.
    00:07:46,979So, that's two pieces of information
    00:07:48,773I know I'm going to need.
    00:07:49,996So why don't I start, I'm gonna just say,
    00:07:53,228and this is the way actual gear systems work,
    00:07:55,848you have one gear that is sort of the primary moving gear,
    00:07:59,616and so I'm gonna say gear one is that gear.
    00:08:02,451This is the gear that everything else moves based off of.
    00:08:05,640So, I'm gonna make it a different color,
    00:08:07,459just so I can remember that.
    00:08:09,796And I could maybe even lock it, alright?
    00:08:13,225So in this gear control,
    00:08:15,524I need to add one more expression here,
    00:08:18,717or expression controller.
    00:08:20,391And this is what I discovered.
    00:08:22,816So in order to figure out how slow or fast this gear
    00:08:26,655needs to move, what you're supposed to do is
    00:08:29,169divide the number of teeth in the main gear
    00:08:32,394by the number of teeth in the next gear.
    00:08:36,319So I counted this gear has 18 teeth in it.
    00:08:41,330So what I'm gonna do is I'm going to add a slider control.
    00:08:47,864Slider controls are just handy
    00:08:49,635because they let you just type in a number,
    00:08:51,599and I'm gonna rename this
    00:08:53,870gear teeth count.
    00:09:00,163That'll put 18 there.
    00:09:02,605And the reason I'm not hard coding this 18 in somewhere
    00:09:05,958is just in case you ever decided to make this the main gear.
    00:09:11,693It just makes everything easier if you
    00:09:13,972kinda future proof it.
    00:09:15,079So, gear teeth count is 18, and again
    00:09:17,325this is referring to the main gear, this first gear.
    00:09:21,051So, on the next gear, I'm gonna need two controls.
    00:09:24,514One control is going to be the number of teeth on this gear.
    00:09:29,563So I'll just say Number of Teeth.
    00:09:33,020Then the next thing I'm gonna need to tell it is,
    00:09:37,774is it rotating clockwise or counterclockwise?
    00:09:42,910So to do that, I could just add another expression control
    00:09:48,160called a check box control.
    00:09:51,350And this just lets you turn something on or off like this.
    00:09:54,154So I could say, clockwise question mark, and there ya go.
    00:09:58,981There's my controls.
    00:09:59,903So now let's wire these things together
    00:10:01,566and figure out how the heck this is gonna work.
    00:10:04,027So when I do this, I'm gonna use more expression code
    00:10:08,449than you actually need because I find it's better
    00:10:12,782to do that, it makes it easier to read sometimes.
    00:10:16,423When you start writing a lot of expressions
    00:10:18,586and I use a lot of expressions.
    00:10:20,627Probably every project I use them.
    00:10:23,267It's very easy to forget what the expression's doing
    00:10:26,584or why you did something a certain way,
    00:10:28,303so it's really nice to make it a little bit easier to read.
    00:10:32,254So, let's open up the rotation property of gear two,
    00:10:37,015delete the expression that's in there,
    00:10:39,072and let's start with a new expression.
    00:10:41,029So, I'm gonna option click on the stopwatch,
    00:10:44,289and first thing I wanna do is define the variables
    00:10:49,414that I'm gonna be dealing with here.
    00:10:51,686And again, you don't need to do this but it just makes it
    00:10:54,100easier to think about and easier to read.
    00:10:56,879So, first thing I wanna know
    00:10:58,155is the number of teeth in this gear.
    00:11:01,171So I'm just gonna make a variable called num teeth.
    00:11:05,431And you see the way I'm typing this,
    00:11:06,924where I have lowercase and then on a new word
    00:11:10,311I just do an initial caps.
    00:11:13,044That's very common way if you ever see code
    00:11:16,797or talk to a programmer, that's how a lot of them do it.
    00:11:20,195So I've kinda adopted that.
    00:11:21,658So the number of teeth equals
    00:11:24,123whatever this slider is set to.
    00:11:27,252So I'm just pick whipping.
    00:11:28,557Every line in your expression needs to end with a semicolon.
    00:11:32,829That's very important.
    00:11:34,382It's like the period at the end of a sentence.
    00:11:37,438The next thing I need to know is,
    00:11:39,622is this clockwise checkbox checked?
    00:11:42,638So I'm just gonna say clockwise equals
    00:11:49,242Now what the heck does that mean?
    00:11:50,872This first expression makes sense, right?
    00:11:53,072The number of teeth equals whatever this number is,
    00:11:55,469but the second one doesn't really make sense.
    00:11:58,237What this checkbox actually does is it returns a zero
    00:12:03,559if it's not checked, and a one if it is checked.
    00:12:07,228So this clockwise variable will either be zero or one, okay?
    00:12:11,248And I'll show you what to do with that in a minute.
    00:12:13,492So the next thing we need to know, is we need to know,
    00:12:19,010I'm just gonna hit enter for a minute,
    00:12:20,399coming back up here.
    00:12:21,603So we also need to know what this angle control is set to
    00:12:25,828and what this main gear teeth count is set to.
    00:12:29,710In fact, let me rename that so it's a little bit clearer.
    00:12:33,204This is the main gear teeth count.
    00:12:35,965So what I'm gonna do is I'm gonna make sure that both
    00:12:38,403of these properties are opened up on the timeline so that
    00:12:42,565I can access this layer but still pick whip to them.
    00:12:47,660So, let's go back to our expression and keep adding stuff.
    00:12:49,468So we need to know the main gear teeth.
    00:12:55,659So the number of teeth in the main gear
    00:12:58,422is gonna equal this slider.
    00:13:03,192And then the last thing we need to know
    00:13:04,695is the control angle.
    00:13:07,269So what is this gear controls, angle control set to?
    00:13:10,415And I'll just call it main control,
    00:13:15,440equals that.
    00:13:17,559Okay, so now in this expression,
    00:13:20,261and this is one of the things that
    00:13:21,776bothers me about after effects.
    00:13:23,339I wish it would do a better job of
    00:13:24,712giving you more room for expressions when you need.
    00:13:27,803If you're running out of room,
    00:13:28,848you can just sort of move your mouse over the
    00:13:31,426bottom sort of boundary of that box,
    00:13:34,731and then you can stretch it out.
    00:13:36,865You get a little more room.
    00:13:38,448Okay, so we've got our variables now.
    00:13:40,557So let's think about the way this works.
    00:13:42,582So, in order to find out how much faster or slower
    00:13:47,377this gear is going to turn than the main gear,
    00:13:50,948we divide this number of teeth by this number of teeth.
    00:13:57,243We're gonna try to figure out the ratio of the speed
    00:14:03,167that we wanna basically multiply times the speed
    00:14:06,080to get the new speed for our smaller gear.
    00:14:09,084So let's make a variable called ratio.
    00:14:11,152We're gonna say ratio equals, and it's gonna be this number,
    00:14:16,717the number of teeth in the main gear.
    00:14:19,086So main gear teeth
    00:14:23,421divided by the number of teeth in this,
    00:14:26,414which is this variable, num teeth.
    00:14:30,945So type that in, semicolon.
    00:14:32,728Great, so that's the ratio.
    00:14:35,931Now, there's another part to this, which is
    00:14:38,935is it gonna turn clockwise or counterclockwise.
    00:14:41,794So now, this is where it gets a little bit more complicated
    00:14:45,764and again with expressions,
    00:14:48,051once you use an expression twice,
    00:14:51,817you're gonna remember it and it's gonna work for you.
    00:14:54,815The first time you try to do it,
    00:14:56,363you're gonna type something in wrong,
    00:14:57,545you're gonna screw it up,
    00:14:58,539and you're gonna have to spend an hour figuring that out.
    00:15:00,666And I'm sorry, but that's just the (laughs) way it works.
    00:15:03,444Once you do it the second time, then you'll remember it.
    00:15:05,302At least that's how it works with me.
    00:15:06,826So we sort of have two cases here.
    00:15:09,776If it's turning clockwise,
    00:15:13,090let's say that the angle of this gear here is 90 degrees.
    00:15:17,345Well, this gear needs to be slightly less than that
    00:15:21,405because it's got less teeth so it's turning slower.
    00:15:24,612So, that means that we have to basically multiply
    00:15:31,072this angle times the ratio, if that makes sense.
    00:15:35,171If it's turning counterclockwise, though,
    00:15:37,419it's actually gotta go backwards
    00:15:39,687so it has to turn in a negative direction,
    00:15:42,466which means we need to multiply the ratio by negative one
    00:15:46,461to get this to turn the right way.
    00:15:49,127So, when you have any kind of situation
    00:15:52,463where if one thing happens, do this,
    00:15:54,962otherwise, do something else,
    00:15:57,982the way you do that with expressions
    00:15:59,377is you use an if statement.
    00:16:02,338And these are pretty simple logically.
    00:16:04,830The only tricky thing about them is that
    00:16:06,898you have to remember the syntax and parenthesis and brackets
    00:16:10,616and making sure everything is formatted correctly,
    00:16:13,298otherwise it won't work.
    00:16:14,392So I'm gonna show you how to do that.
    00:16:15,844First thing we're gonna do is we're gonna say if,
    00:16:18,336'kay, that's easy.
    00:16:20,677Now, we need to put in parenthesis the thing
    00:16:25,593that we're testing, and what we are testing is,
    00:16:28,556is the clockwise variable,
    00:16:31,996so is clockwise equal to one.
    00:16:37,170Now you'll see I put two equal signs in there.
    00:16:41,208When you use an if statement,
    00:16:44,413and you wanna see if something's equal to,
    00:16:48,131equal to a specific number, you have to use two equal signs.
    00:16:52,161There's some programming reasons why
    00:16:53,990it's not one equal sign, I'm not gonna get into that.
    00:16:55,929Just remember it has to be two equal signs.
    00:16:58,841Alright, if clockwise equals one,
    00:17:01,972meaning is this checkbox checked.
    00:17:04,802Alright, now we're gonna tell it,
    00:17:06,338what do you do if clockwise is one.
    00:17:08,451And the way you do this is you open a bracket,
    00:17:12,481and now whatever I put after that bracket
    00:17:15,538is what will happen if clockwise is one.
    00:17:18,284Excuse me.
    00:17:20,295And you can have multiple lines.
    00:17:22,227You can have a whole bunch of things happen.
    00:17:24,629And generally, when you're coding,
    00:17:29,057it's just sort of common practice to go to the next line,
    00:17:33,240so you open up this bracket here, you go to the next line,
    00:17:35,972and you hit tab to go over a little bit.
    00:17:38,323It makes it a little bit easier to read.
    00:17:41,084Now, if clockwise is one, what's gonna happen is
    00:17:45,314we're just gonna multiply the ratio times the main control.
    00:17:51,093So we're gonna say if clockwise equals one then the answer
    00:17:56,088to this, the actual number we wanna feed into rotation
    00:18:01,582is ratio, this ratio variable,
    00:18:04,751times main control.
    00:18:09,328That's it.
    00:18:10,666So, that's the end of this part
    00:18:13,223so I'm gonna close the bracket.
    00:18:16,965Now, you can stop there if you want to,
    00:18:20,093or you can add another little piece, which is else.
    00:18:25,913And then you open another bracket and go to the next line,
    00:18:28,159and what this is saying, and you can probably figure it out
    00:18:31,154just because it makes sense, if clockwise is one, do this.
    00:18:36,505Else, or otherwise, do something else.
    00:18:39,558If it's supposed to go counterclockwise,
    00:18:43,226then what we're gonna do is,
    00:18:44,658we're gonna return ratio times main control
    00:18:50,241times negative one.
    00:18:52,693And that negative one is just gonna
    00:18:55,008make that rotation happen backwards.
    00:18:59,632Go to the next line.
    00:19:00,593Close the brackets.
    00:19:02,795And we're getting an error so let's take a look.
    00:19:06,332Alright, okay.
    00:19:07,173So this is good, this is great here.
    00:19:10,307So right now, let me hit okay.
    00:19:13,555What it's telling me is that it's trying to divide something
    00:19:18,918by zero, and obviously you can't divide by zero,
    00:19:21,175and that's because this number of teeth
    00:19:22,754has been left set at zero.
    00:19:24,941Now, obviously, you're never gonna have a gear
    00:19:27,421with zero teeth so that's always gonna have a number in it.
    00:19:30,316But I'm glad you guys saw that.
    00:19:32,629Expressions are not like bulletproof software code.
    00:19:36,280If you were programming something,
    00:19:39,021if I was really trying to button this rig up,
    00:19:41,150and make it so you would never have errors,
    00:19:42,965I would say if clockwise is one, do this.
    00:19:46,810Otherwise, do this.
    00:19:47,643I would also check to see if this number is set to zero,
    00:19:52,371then I need to tell the expression how to handle that.
    00:19:56,818Now, I'm not gonna do that but just so you guys know,
    00:19:59,597that's why that little error message came up.
    00:20:01,802Alright, so let's figure out how many
    00:20:03,212teeth this gear actually has.
    00:20:05,860So let's start with this one,
    00:20:07,496that's in between the two gears.
    00:20:09,306So you've got one, two, three, four, five, six, seven,
    00:20:11,287eight, nine, 10, 11, 12, 13, 14, 15, 16 gears on that one.
    00:20:16,16816 teeth, so we type in 16.
    00:20:19,704Now, you can see that the expression is not turned on
    00:20:22,830because you've got this little icon,
    00:20:25,528the equal sign with the slash through.
    00:20:27,371So if I click that now, everything should work
    00:20:30,536because we are no longer dividing by zero.
    00:20:32,662So just remember that you need to make sure that this slider
    00:20:36,815is not set to zero if you want this expression to work.
    00:20:40,779So let's see what's happening now.
    00:20:42,752So, it's going the wrong way because it's set to clockwise.
    00:20:47,075Now, if we uncheck that, hey look at that.
    00:20:51,420It's working.
    00:20:52,485And in fact, if we go through it frame by frame,
    00:20:55,837you can see that the teeth never actually intersect.
    00:21:00,211It's working perfectly on the first try
    00:21:02,954which is kind of amazing.
    00:21:04,473So let's stretch this T frame out here
    00:21:07,353so we can get a better look at this.
    00:21:11,793Now, I wanna show you something
    00:21:15,530because there's one other piece that we need to add
    00:21:18,176to this expression to really make it versatile.
    00:21:21,752And so let's say that I had this gear here.
    00:21:27,814And that's exactly where I want that gear.
    00:21:30,201That's exactly where I want that gear.
    00:21:31,911The problem is that the teeth are intersecting.
    00:21:34,297Now they're moving at the right speed,
    00:21:35,679but the problem is they just need to offset
    00:21:37,710this rotation a little bit,
    00:21:39,661so that it will fit properly in this gear.
    00:21:42,830So, now I'm realizing, I also need the ability
    00:21:47,400to just offset the rotation a few degrees
    00:21:51,012in either direction to make it fit perfectly.
    00:21:53,749So, with that gear selected, I'm gonna add another
    00:21:57,276slider control and I'm just gonna call this rotation
    00:22:04,805And so now where is this gonna plug in?
    00:22:07,445So let's bring up our rotation expression.
    00:22:12,270Right there.
    00:22:14,585And let's think about this.
    00:22:16,043So what I need to be able to do,
    00:22:18,686first let me define this as a variable,
    00:22:20,401make it a little bit easier to deal with.
    00:22:22,264I'll just call it offset equals
    00:22:30,372And really all I need to do is add that offset
    00:22:34,584to whatever the result is, and that should do it.
    00:22:38,579Because if it's zero, it's not gonna change the answer,
    00:22:41,192and then I can make it positive or negative to kind of
    00:22:43,993turn it one direction or the other,
    00:22:45,275so why don't we just say if clockwise is one,
    00:22:48,627ratio times main control, plus
    00:22:55,252And then I'll just add the same thing down here,
    00:22:58,329plus offset.
    00:23:01,223And let's see if it works.
    00:23:02,366So now if I adjust this expression,
    00:23:04,875you can see I can just adjust it,
    00:23:09,119and then it should work perfectly.
    00:23:10,871And now if I move it back here, I can just adjust it,
    00:23:16,540so that it works at that position.
    00:23:18,392So that's pretty much the gear rig.
    00:23:21,326Now we're ready to go.
    00:23:22,469So now the way that you apply this to the other gears,
    00:23:27,707is you first copy the slider controls,
    00:23:31,715because if you copy the expression first,
    00:23:35,053that expression is looking for slider controls
    00:23:37,896and the angle control and the checkbox,
    00:23:40,075it's looking for controls that are not there
    00:23:42,851and it will give you an error.
    00:23:44,070So it's just a little bit easier to do it this way first.
    00:23:46,710Copy the sliders.
    00:23:48,578Let's paste them.
    00:23:50,913And then, you can just copy the rotation
    00:23:57,512and it will copy the expression that's on there,
    00:23:59,777so let me just paste that here, too.
    00:24:02,809And now we can see if it's working on these gears.
    00:24:05,394So here's gear three and I'll put it down here.
    00:24:08,723Now, gear three, how many teeth does it have, right?
    00:24:11,240Like if we just hit play, it's obviously not working right.
    00:24:15,087But, well first, we know it's going the wrong direction,
    00:24:17,491so let's just hit the clockwise checkbox.
    00:24:20,016So now, it'll go clockwise.
    00:24:22,774And then we just need to count the teeth.
    00:24:24,977So you've got one in there, then two, three, four,
    00:24:27,393five, six, seven, eight, nine.
    00:24:29,042So nine teeth.
    00:24:30,632So if you just type in nine in there,
    00:24:33,934now that one works perfectly, too.
    00:24:36,588Beautiful thing, and then if you need to nudge it
    00:24:38,574a little bit, if you just want it to be a little bit
    00:24:40,536more perfect, if you actually want it to look like
    00:24:45,344the teeth are touching and it's pushing the teeth
    00:24:47,790just the little bit, you can get really precise.
    00:24:52,331And we could go back and then adjust gear two.
    00:24:58,322And this is the power of expressions because
    00:25:00,443it lets you be so precise with stuff like this.
    00:25:03,815If you were just trying to manually key frame this,
    00:25:06,663it would be a nightmare.
    00:25:08,861But with expressions, it's actually pretty easy
    00:25:10,529once you wrap your head around the math,
    00:25:14,961and I'm sorry, again, with the math,
    00:25:17,025but once you wrap your head around it,
    00:25:19,173and it's not that difficult,
    00:25:22,350you can do all this stuff so fast.
    00:25:24,750Alright, so obviously, this one,
    00:25:26,079it's turning the right direction,
    00:25:27,180it's just not turning fast enough, and it's got six teeth.
    00:25:30,822So we just type six in there,
    00:25:33,106and then we can adjust the offset of it.
    00:25:38,825Alright, and actually, I want this to look like
    00:25:42,243it's being pushed by this one, so there we go.
    00:25:46,647So there we go, right?
    00:25:48,980Gears turning perfectly, teeth not intersecting,
    00:25:53,719and that's all there is to it.
    00:25:56,455It's really kind of that simple.
    00:25:57,858You're done.
    00:25:58,691The rest of it is just copying and pasting
    00:26:02,119and arranging the gears the way you want.
    00:26:05,515One good thing to know, if I take this gear, for example,
    00:26:08,561and just duplicate it and bring it over here,
    00:26:11,943this little expression, it doesn't break
    00:26:15,835if you scale things down a little bit.
    00:26:18,635You can get away with scaling these just a little bit.
    00:26:22,517You see it still works, it doesn't intersect.
    00:26:26,338So, you can get a ton of variety,
    00:26:28,969and of course, I only made four little gears here,
    00:26:31,967'cause I was kind of being lazy and I just didn't want to
    00:26:35,340spend that much time making gears, but you can see,
    00:26:38,958even with just four gears,
    00:26:41,067just messing with the scale a little bit.
    00:26:43,122And of course, these are vectors,
    00:26:44,539so I can just turn on continuous rasterize
    00:26:49,105and have perfect shapes every single time.
    00:26:53,079But you can get a ton of variety and, of course,
    00:26:55,878you can play with color and all that stuff.
    00:26:58,255But now that you've built this little rig
    00:27:00,878with simple controls that any after effects artist could
    00:27:05,580figure out if you just, you know, shot 'em a little e-mail.
    00:27:08,803Now, you're good to go.
    00:27:09,763And again, the beauty of having this gear controller
    00:27:13,688do all the work is that now,
    00:27:15,951instead of having just like a simple move,
    00:27:18,839maybe what you do is you have it sit still for a few frames,
    00:27:23,056and then maybe it's like someone turned the motor on
    00:27:26,099and it kind of kicks back a little bit, like that,
    00:27:30,635hangs there for a couple frames,
    00:27:32,310and then it kinda shoots forward,
    00:27:36,480just kind of goes a little too fast,
    00:27:38,797and then kind of catches itself, pauses,
    00:27:42,918and then it starts going.
    00:27:44,295And you know, I don't know how this is gonna look,
    00:27:47,055but let's see if I, let's see if we do a little ram preview.
    00:27:50,992You get like a little, like a little sputter.
    00:27:54,839(makes squelching noise)
    00:27:55,843And you need a little sound effect.
    00:27:56,722You need a little, you know (imitates flatulence)
    00:27:58,523or something.
    00:28:00,089And then you have all this control,
    00:28:02,122you can go to the curve editor,
    00:28:03,574and you can say, okay once it starts going,
    00:28:05,913I want it to really slowly get going,
    00:28:07,900and then I want it to end up being more or less linear.
    00:28:12,029And then you can, let's drop down in here,
    00:28:14,412and let's have it really catch on that first, there we go.
    00:28:20,275Yeah, you see that?
    00:28:21,206And then it starts turning slowly,
    00:28:23,049and maybe that's too slowly,
    00:28:24,540so we wanna pull that handle back in.
    00:28:30,087Yeah, there we go.
    00:28:31,619Alright, so now you have all the control
    00:28:34,767with this one key frame, but all these gears are gonna
    00:28:37,637fit perfectly and they're gonna work perfectly.
    00:28:41,842And you're gonna, you're just gonna have a much easier time.
    00:28:44,355So, I hope that this was useful.
    00:28:47,292There was a lot of other stuff I didn't get into,
    00:28:50,290that I actually used to make the animation that you saw
    00:28:54,450at the beginning of this tutorial,
    00:28:55,944and if you have any questions about that stuff,
    00:28:58,884please leave me a comment.
    00:29:01,438You can find me on Twitter, on Facebook,
    00:29:04,186and I'm definitely,
    00:29:06,354I'm leaving some of this stuff out there because I wanna
    00:29:10,331find out what you guys are interested in learning.
    00:29:13,409Interesting fact, I actually used an expression to colorize
    00:29:17,093the gears so that I could just sort of pick four colors
    00:29:20,576and it would randomly select a color for me
    00:29:23,483so I didn't have to do that either.
    00:29:25,350I'm a enormous Family Guy fan
    00:29:26,866so I hope you guys enjoy that little Easter egg there.
    00:29:30,522Anyway, I hope this was useful, informative.
    00:29:35,184Thank you guys.
    00:29:36,231As always, I will see you guys next time.
    00:29:39,995We're in 30 days of after effects here.
    00:29:42,065There's a lot more content coming.
    00:29:43,748So stay tuned.
    00:29:45,601Thank you for hanging out.
    00:29:46,600I hope this helped you grasp
    00:29:48,003how much of a time saver expressions can be.
    00:29:50,577If you have any questions, let us know on the site.
    00:29:53,285And if you learned something valuable from this video,
    00:29:55,168please share it around.
    00:29:56,604It really helps us spread the word about School of Motion
    00:29:59,419and we truly appreciate it.
    00:30:01,252Don't forget to sign up for a free student account
    00:30:03,215to access the project files and the expressions
    00:30:05,552from the lesson you just watched.
    00:30:06,963Plus, a whole bunch of other awesomeness.
    00:30:09,814I'll see you on the next one.
    00:30:12,028(bouncing noises)
    00:30:14,747(upbeat music)