Create a Carousel Rig in After Effects

It's time for you to harness the power of code and turn it into your friend. In this lesson Joey is going to help you build off of those fundamentals you learned in the Intro to After Effects Expressions tutorial. You'll be building a fully-featured carousel rig that’s totally customizable and easy to use.

You'll learn a bunch of new skills from how to find expressions online and customize them, to creating automatic behavior using if-then statements, creating “remote” controls, and using trial and error to troubleshoot your expressions. There’s also plenty of other little tips and tricks in this video that you'll pick up along the way.

 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.

For some more practice, check out After Effects Expressions 101.

    • cannot download project i use mac

    • Thanks for writing. We just replaced the file with a corrected version. Please try downloading the new version from the same page.

    00:00:00,771- [Announcer] If you can't come in Saturday,
    00:00:03,917don't bother coming in Sunday.
    00:00:06,938(light techno music)
    00:00:11,114(bouncing and whooshing)
    00:00:14,864(upbeat techno music)
    00:00:22,162- Hey there, Joey here for School of Motion.
    00:00:23,990And in this lesson we are going to create
    00:00:25,719a pretty cool rig using expressions.
    00:00:28,222By the end of this lesson, you'll have built
    00:00:30,238your very own carousel rig that you can use
    00:00:32,628over and over again in different projects.
    00:00:34,644And you won't just have a cool rig.
    00:00:36,613You'll also have a better understanding
    00:00:38,280of how expressions work in After Effects,
    00:00:41,032which is knowledge you can use to start building
    00:00:43,392your own tool like this one.
    00:00:45,645Don't forget to sign up for our free student account
    00:00:47,883so you can grab the rig and expressions from this lesson
    00:00:50,605as well as assets from any other lesson on this site.
    00:00:53,627And now, let's jump in.
    00:00:56,090So, this comp here is sort of the end result
    00:01:00,770of our Expression exercise here.
    00:01:04,521And you can see I have a bunch of these
    00:01:06,549freeware icons I downloaded
    00:01:08,270just to sort of show you guys
    00:01:10,365how easy it is to put different images
    00:01:13,388in each of the slots in this carousel.
    00:01:16,641And if we look at the comp here
    00:01:18,484you can see that I have a couple of lights
    00:01:21,178and a camera in there.
    00:01:22,964And really those are just so we can sort of move around
    00:01:26,778and see what's going on with this rig.
    00:01:30,655But the meat of this is happening
    00:01:33,242in this controller null right here
    00:01:35,188where we have some expression sliders and angle controls.
    00:01:39,289And also these Precomps here.
    00:01:42,221These Precomps are the actual images
    00:01:45,277that are being sort of arranged in this carousel.
    00:01:49,642And this controller is rigged up
    00:01:52,257with a radius slider here,
    00:01:55,238a rotation control which will let us rotate the carousel.
    00:02:01,071There's also x, y, and z offset parameters here.
    00:02:05,402The reason for that is if we wanted to
    00:02:07,138move the camera up top like this,
    00:02:10,510we could actually rotate
    00:02:14,201all of the icons.
    00:02:15,978Let me zoom out here so we can see everything.
    00:02:19,303So we could actually rotate this
    00:02:22,442looking straight down at it
    00:02:23,855if we wanted that for example.
    00:02:25,279And you know we could make the radius smaller,
    00:02:28,547we could use the z.
    00:02:30,160So this is really, really controllable.
    00:02:32,752And then I added one more cool feature
    00:02:34,768which is this orient outward checkbox.
    00:02:37,083And if you click that,
    00:02:39,130you'll see that it actually orients all of the images
    00:02:42,232facing outward.
    00:02:43,695And then we need to adjust the offset a little bit
    00:02:45,687so they're kind of facing the way we want.
    00:02:48,258And then so if you were doing kind of like a
    00:02:51,317little wheel graphic where you're sort of focusing on
    00:02:57,896whichever images at the bottom of this
    00:03:01,731you could set up a pretty quick little preset
    00:03:04,855where you could just kind of cycle through these things.
    00:03:07,208So anyway, this is very flexible
    00:03:09,348and this is the type of thing
    00:03:10,930that when I was doing this type of video a lot,
    00:03:13,651I would build these things.
    00:03:15,694And when I would freelance I would bring a drive
    00:03:18,481so I had all of these things with me.
    00:03:20,419And that way, I kind of had my bag of tricks.
    00:03:24,555And if you are on staff somewhere,
    00:03:27,983if you're freelance,
    00:03:29,065this kind of stuff really, really will separate you.
    00:03:32,764Every motion designer has their strengths and weaknesses
    00:03:36,175and once you kind of build up your bag of tricks,
    00:03:38,813you'd be much, much more marketable.
    00:03:41,166So anyway, I'm gonna show you step by step
    00:03:43,015how I built this.
    00:03:44,226And I'm also gonna try and teach you guys
    00:03:45,925how I approached this
    00:03:47,479because this was sort of complicated
    00:03:51,228but I didn't know every single step of how to build this
    00:03:55,910until I built it.
    00:03:56,943And I had to look online
    00:03:58,729and look in the After Effects help file.
    00:04:01,698So I kind of want to show you guys
    00:04:03,097the process I used to build it.
    00:04:05,339So, what I'm gonna do
    00:04:06,950is I've already created a blank comp here.
    00:04:10,089There's nothing in it.
    00:04:11,742And so the first thing I'm gonna do
    00:04:13,066is I'm gonna make a new solid.
    00:04:15,212So I'm gonna go Layer > New > Solid.
    00:04:18,324And I'm gonna make it small, 200 by 200.
    00:04:20,968I'm doing this just so that I can be very interactive
    00:04:23,817while I'm doing the tutorial.
    00:04:24,912You can make it whatever size you want to.
    00:04:26,925All right, so we've got this
    00:04:29,169nice little solid here.
    00:04:30,680So the first thing I needed to figure out
    00:04:33,043was how am I gonna get all of these solids
    00:04:36,827to move in a circle?
    00:04:39,216And there's plenty of ways to do that
    00:04:41,997but I also knew that I wanted this to be
    00:04:45,664really easily customizable.
    00:04:47,770And actually, let me show you guys one more feature
    00:04:50,276that's built into this rig too.
    00:04:52,093You can see I have 10 images here.
    00:04:54,884I've built the rig so if I add more images,
    00:04:57,620it actually spaces them out automatically.
    00:05:00,613And if I delete images,
    00:05:02,224it spaces them out automatically.
    00:05:04,225So you can easily add as many or as few as you want here.
    00:05:07,693And I knew that was something I was gonna want to build in
    00:05:09,703to this rig.
    00:05:12,052So, to start with I knew I wasn't going to do
    00:05:16,748something like this
    00:05:17,866where I would make this a 3D layer.
    00:05:20,586And let's say I just moved it 200 pixels backwards in z.
    00:05:25,866I'm gonna make a new null here, make that 3D.
    00:05:29,979I'm gonna parent this solid to this null
    00:05:33,543and I'm just gonna rotate this null
    00:05:35,632on the y axis.
    00:05:36,798And you can see we're getting a circular motion with it.
    00:05:40,362The problem is,
    00:05:42,839this solid is parented to this null.
    00:05:45,751If I had two solids,
    00:05:49,097I would have to
    00:05:51,861somehow figure out how to move this solid
    00:05:55,075into the right spot in relation to the null
    00:06:00,705and then I could rotate the null.
    00:06:02,327And this works too.
    00:06:03,879But what if I wanted these solids to always face the camera,
    00:06:07,300to always face forward.
    00:06:08,934Well that would be,
    00:06:11,843that would be possible
    00:06:14,248with some more expressions.
    00:06:15,313But it would be really difficult to figure out the math
    00:06:17,763of how to,
    00:06:18,956let's say I had a dozen of these layers.
    00:06:21,046It would be pretty difficult to figure out how to
    00:06:22,747place them around this null.
    00:06:25,164So what I thought I would try,
    00:06:27,267let me just get rid of these for a second.
    00:06:30,116What I thought might be a little easier to figure out
    00:06:32,627is what is the expression I can use to make a layer move
    00:06:38,422in a circle.
    00:06:40,061And I knew that that would be possible because
    00:06:43,122I've been lurking on Creative Cow and
    00:06:47,994and MotionScript
    00:06:49,162For years I've just sort of checked those sites out
    00:06:52,010and I remembered seeing stuff and I knew it was possible.
    00:06:54,734And that's generally how these things start with me.
    00:06:57,152I know it's possible but I don't know how.
    00:06:59,352So I went on Google
    00:07:01,585and I Googled After Effects Expressions circular motion.
    00:07:07,164And this was one of the results that came up.
    00:07:10,720And you know, thank you Dan Johannson
    00:07:14,219from April 12th, 2010.
    00:07:16,652He typed out a couple of cool expressions here.
    00:07:20,651One is to create circular motion.
    00:07:24,521One is to create spiral motion.
    00:07:26,561And I haven't tried that one but that's pretty cool.
    00:07:28,891So what I did was I just copied and pasted
    00:07:31,953the circular motion script.
    00:07:37,444Again, if you haven't watched the After Effects Expressions
    00:07:40,638basic video,
    00:07:41,689I recommend watching that.
    00:07:42,935'Cause I'm gonna kind of buzz through how I apply these
    00:07:45,949expressions and edit them and things like that.
    00:07:48,379All right, so the first thing I did
    00:07:50,615was apply the expression to the position key frame
    00:07:54,469of this solid.
    00:07:56,121All right, so I'm just gonna paste that in
    00:07:59,554and if I scrub through this,
    00:08:01,615you'll see I'm getting this moving in a perfect circle.
    00:08:06,818Now let's look at this expression because
    00:08:09,433this is pretty common to
    00:08:12,950look on a website and copy and paste an expression
    00:08:15,588and really not understand what it's doing.
    00:08:17,812And I never like to do that because I usually like
    00:08:20,576to customize things
    00:08:22,085and make them controllable.
    00:08:24,383Right now this is not very controllable.
    00:08:26,246So I wanted to look at it and understand
    00:08:28,434what it's doing, okay.
    00:08:30,441So the first thing I see is radius equals 300.
    00:08:34,084Now, if you are new to writing expressions
    00:08:37,538and you have never done any sort of computer programming,
    00:08:41,081this may not make sense.
    00:08:42,089But if you have any experience computer programming,
    00:08:45,244expressions work a lot in the same way.
    00:08:48,908So what is happening here is whoever wrote this expression
    00:08:52,470created a variable called radius.
    00:08:55,141And you can call variables almost anything you want
    00:08:58,025as long as they don't share a name with a function
    00:09:01,049that you can use in After Effects.
    00:09:03,354So this person is setting the radius of the circle to 300.
    00:09:08,070Then for the angle,
    00:09:10,062and this angle I assume this is telling this layer
    00:09:13,574which angle along the 360 degrees of the circle
    00:09:18,310am I going to place this layer at.
    00:09:21,530Well the angle is set to time times 200.
    00:09:25,381So what that's telling me is that every second
    00:09:29,024of the After Effects comp,
    00:09:30,599this layer is going to move 200 degrees around the circle.
    00:09:34,581So it should take a little over a second and a half
    00:09:40,507to do a complete rotation.
    00:09:43,165And if we start at zero,
    00:09:46,355then you'll see that this circle is
    00:09:49,435sort of right at three o'clock here.
    00:09:52,081And if we move forward a couple of seconds,
    00:09:55,473now it's back where it started.
    00:09:57,338So it's a little over a second and a half.
    00:09:59,920We're at 24 frames a second,
    00:10:01,550so that's over a second and a half.
    00:10:04,727So that's how this layer is moving right now.
    00:10:07,253It's using the time of the comp
    00:10:09,424multiplying the second of the comp times 200 degrees
    00:10:14,819and moving that around the circle.
    00:10:16,455Now how is it actually positioning that layer
    00:10:19,288around a circle?
    00:10:21,554So that's what all this gibberish is.
    00:10:23,611And this is some hardcore
    00:10:26,746junior high geometry here.
    00:10:29,410And basically what's happening is
    00:10:31,838we have an x and a y variable
    00:10:34,483which are later going to be turned into the x and y value
    00:10:40,150of our layer.
    00:10:41,738And you can see we're using the math function,
    00:10:45,559specifically the cosine,
    00:10:47,895and it's doing this conversion of degrees to radians.
    00:10:51,987That's a function in After Effects.
    00:10:54,127That converts this 200 degrees into radians.
    00:10:58,648And I have to just stop and tell you
    00:11:01,968that the only reason I can explain this
    00:11:03,590is because I had to go back and look it up.
    00:11:07,833I'm okay at math
    00:11:09,262but I don't use cosines and sines and tangents every day.
    00:11:13,975So I had to look this up.
    00:11:15,974And I didn't understand this when I first looked at it.
    00:11:18,545But that's okay,
    00:11:20,325because as a motion designer,
    00:11:22,062you shouldn't be afraid of math.
    00:11:23,765You should be able to copy and paste things
    00:11:26,148but then just understand just enough
    00:11:29,060so that you can change it
    00:11:30,679to do what you want it to do.
    00:11:33,380This degrees to radians function is interesting.
    00:11:37,758If you remember back in geometry,
    00:11:41,074whenever you're doing things with cosines and sines,
    00:11:46,709you have to work with pi.
    00:11:48,717And there's actually a way of expressing angles
    00:11:52,300using pi.
    00:11:54,244So 360 degrees of a circle,
    00:11:58,534I believe is actually two pi.
    00:12:01,109So this basic converts the 200 degrees into
    00:12:05,420a fraction of pi
    00:12:06,502and then the cosine can do its thing to it.
    00:12:09,048So, you don't really need to know all that.
    00:12:11,299I just felt like telling you
    00:12:12,859and I'm sorry if it hurt your head at all.
    00:12:15,458All right, so x is using the cosine,
    00:12:18,454y is using the sine,
    00:12:20,208z is zero.
    00:12:21,597So since there's an x, y, and z,
    00:12:23,672this tells me that this will work
    00:12:25,600on a 3D layer.
    00:12:27,168Now it's currently only using x and y
    00:12:28,804so it's not gonna go backwards in space at all.
    00:12:30,815It's just gonna go up and down.
    00:12:32,447But that's okay, I can modify that.
    00:12:35,706All right, so then the center of the circle.
    00:12:38,054And this is telling me where the center is, all right.
    00:12:41,603Right now the center is set to 640, 360, zero.
    00:12:46,153And then this last function, add.
    00:12:49,731This is basically saying take the center
    00:12:54,052and whatever the result of all this geometry math here is,
    00:12:58,168let's add that to the center.
    00:13:00,482So we can put the center wherever we want
    00:13:02,554and then move this layer in a circle around it.
    00:13:05,420So if I set this center to zero, zero, zero,
    00:13:11,089just to show you guys what it's doing.
    00:13:13,406You can see that now the center's actually up here
    00:13:15,733and so the layer is moving around it.
    00:13:18,750And we don't see it most of the time
    00:13:20,274until it comes back into the frame.
    00:13:22,463And if I zoom out you can see what it's doing.
    00:13:25,458Cool, all right, so now I understood
    00:13:27,774what this expression was telling me.
    00:13:30,676So now I needed to figure out how I could control it.
    00:13:33,734So the first thing I wanted to do,
    00:13:35,061I knew I wanted this carousel to be 3D.
    00:13:37,710I wanted it to work in 3D space
    00:13:39,466so I could get that cool perspective shift,
    00:13:43,868that looks cool
    00:13:45,825and impresses clients and all those good things.
    00:13:48,677So I made this a 3D layer.
    00:13:51,268And at this point, I decided well,
    00:13:55,027I'm obviously not gonna just use an orange shape
    00:13:58,478on this carousel.
    00:14:00,099I'm gonna want to be able to put
    00:14:01,456whatever image I want in there.
    00:14:03,482So rather than
    00:14:08,712have to swap out images into this layer,
    00:14:12,521I figured I could just make this a Precomp.
    00:14:15,242So I hit Shift + Command + c.
    00:14:17,896And I'm gonna call this.
    00:14:19,950Let's just call it image_01.
    00:14:22,967And I want to leave all the attributes
    00:14:25,513in my current comp
    00:14:27,080because I have an expression on it.
    00:14:28,974If I pick this,
    00:14:29,922move all attributes into the new composition,
    00:14:32,380it's gonna move this expression into that new composition.
    00:14:35,397And the composition is gonna be the size of this one
    00:14:38,355which is 960 by 540.
    00:14:40,555I actually just want this little piece to have its own comp
    00:14:44,230so that at any point I could dive in,
    00:14:47,051put an image in there,
    00:14:48,187and then have it update, all right.
    00:14:50,176So, I'm gonna have this first option checked and hit OK.
    00:14:53,432All right, so now the expression is still on there.
    00:14:56,752But now, whenever I finish my rig,
    00:14:58,940I can just come in here,
    00:15:00,156I could put an image in here and turn this layer off
    00:15:04,136and then when I come back into my comp
    00:15:08,797I would be able to see the result of it.
    00:15:11,536Let me close this original one.
    00:15:14,031All right so...
    00:15:15,655I knew that I was gonna need to
    00:15:19,165first swap out
    00:15:21,670this y
    00:15:25,298variable here
    00:15:26,363with z.
    00:15:27,515Because I want this layer to move around in z space too.
    00:15:32,757All right, so,
    00:15:33,921what I'm gonna do is just
    00:15:37,019delete this here.
    00:15:40,920And I'm gonna change this y equals to z equals
    00:15:45,880and I'm gonna set y to zero, y eqals zero.
    00:15:49,891And one thing that I also learned,
    00:15:53,211when you write expressions
    00:15:56,140that have multiple lines like this,
    00:15:57,927I generally put a semicolon at the end of every line.
    00:16:01,647And that is a,
    00:16:04,110that's just kind of a programming thing.
    00:16:05,992Certain programming languages require you to do that.
    00:16:08,655It's like putting a period at the end of a sentence.
    00:16:11,043And I was under the impression After Effects Expressions
    00:16:13,846needed that.
    00:16:14,823But apparently they don't because
    00:16:16,704this expression worked without them.
    00:16:19,479For me, because I've been doing it for so long,
    00:16:22,179it looks wrong without those semicolons.
    00:16:24,452So I'm gonna put them in.
    00:16:26,352So now they're all in there.
    00:16:27,747So now I can sleep better tonight.
    00:16:30,333All right, so now we have x,
    00:16:32,692using the cosine,
    00:16:33,525y is now zero,
    00:16:34,622and z is using the sine.
    00:16:36,343And let me set the center to the center of my comp.
    00:16:41,763So this is a 960 by 540 comp.
    00:16:44,439So the center is actually going to be 480, 270.
    00:16:51,090And I put that in the wrong spot.
    00:16:53,926So 480,
    00:16:58,049All right, so now I'm just gonna hit space bar and play this
    00:17:01,272and you can see that now this thing is rotating
    00:17:03,114in a perfect circle.
    00:17:04,582All is good.
    00:17:06,111And what's also cool about doing it this way
    00:17:07,921is that this automatically orients towards us.
    00:17:11,948So you don't have to do any fancy rotation or anything
    00:17:15,473to keep it facing us
    00:17:16,760which you normally would have to do.
    00:17:18,081It's always facing us.
    00:17:20,151So, the first thing to do to create a rig
    00:17:23,886is to create some control
    00:17:25,266so I could actually control the angle of this thing
    00:17:28,100and create the spin
    00:17:31,031at whatever speed and timing I wanted.
    00:17:34,311So if you watched the previous tutorial,
    00:17:36,508you'll know I'm a big fan of using a null.
    00:17:39,509I'm gonna call this null control.
    00:17:42,478And I use the expression controls effects
    00:17:46,112to be able to control things.
    00:17:47,852So what do I need to be able to control?
    00:17:49,679I need to be able to control
    00:17:51,029the radius of the circle
    00:17:53,494because in my head I'm picturing okay,
    00:17:55,502I've got four, five, or six of these.
    00:17:58,438And I need them spaced evenly around a circle.
    00:18:00,754And I want to be able to control how big that circle is.
    00:18:03,397So the other main thing is the angle.
    00:18:07,094I'm gonna want to be able to spin that carousel manually.
    00:18:11,638So I know that this radius and this angle
    00:18:14,694need to be controllable.
    00:18:16,179So I'm gonna grab an expression control,
    00:18:20,515a slider control,
    00:18:22,103and I'm gonna rename that
    00:18:27,701All right, and then for the angle control here, angle,
    00:18:31,613I'm gonna grab an angle control which you see gives me
    00:18:36,337the angle dial.
    00:18:39,731And I'm just gonna call that carousel angle.
    00:18:44,706All right, so now,
    00:18:47,563I'm gonna click on my control there
    00:18:50,228and I'm gonna make sure, I'm gonna hit e,
    00:18:52,677which is gonna expose all my effects,
    00:18:55,243because these are effects even though they don't
    00:18:56,556do anything on their own.
    00:18:58,190And I'm gonna open up these arrows
    00:18:59,982so I can see the numbers underneath them.
    00:19:02,487The reason I'm doing that is because now
    00:19:03,614I'm gonna come into this expression
    00:19:05,600and instead of radius equals 300,
    00:19:08,336I'm gonna highlight the 300 so I can replace that.
    00:19:11,950And I'm gonna use the Expression pick whip
    00:19:14,725and I'm gonna grab this slider right here
    00:19:18,584and I'm gonna hit semicolon.
    00:19:20,501Then I'm gonna come down here where it says
    00:19:22,571angle equals time times 200.
    00:19:25,612I'm gonna highlight time times 200
    00:19:28,548and I'm gonna replace that with carousel angle.
    00:19:33,054All right, so now I can manually set the radius.
    00:19:36,812So let's set the radius to 100.
    00:19:39,546And now this carousel angle will actually rotate
    00:19:43,435that layer for me.
    00:19:45,489All right, so that's great.
    00:19:46,602Now we have a one layer carousel
    00:19:48,645and it's a good start.
    00:19:51,118But we definitely want a little bit more than that.
    00:19:55,572So, now I need to...
    00:20:00,234I want to make sure that this carousel
    00:20:02,910is totally controllable
    00:20:05,632and I could move it around if I wanted to.
    00:20:08,885And I basically want to create
    00:20:10,688as many controls as possible.
    00:20:13,802So right here, where it says center.
    00:20:19,003And it's great because it's spelled,
    00:20:21,211I guess this is probably like the British spelling
    00:20:24,319or something, I don't know.
    00:20:25,774I don't spell it that way.
    00:20:26,855But anyway,
    00:20:28,020right now this center point for this circle
    00:20:30,512is being set manually with these values here.
    00:20:34,326And I don't want to do that.
    00:20:35,864I actually want this control null to be the center
    00:20:40,273of the carousel.
    00:20:41,106So if I wanted to I could move it.
    00:20:43,297Maybe I don't want to.
    00:20:44,722Maybe I just want it in the center.
    00:20:46,666But just in case,
    00:20:48,102I'm gonna make this controllable.
    00:20:49,710So I want the center of the circle to be
    00:20:51,632the position of this control.
    00:20:54,769Now, right now this control is a 2D layer.
    00:20:57,652So that's not gonna work.
    00:20:58,599So I need to make it 3D
    00:21:01,031and then
    00:21:02,646you could do it this way.
    00:21:05,236You could highlight these numbers so you can replace them.
    00:21:09,685And then pick whip to the position of the control.
    00:21:13,821Okay, that's one way to do it.
    00:21:15,648And that will work in this case
    00:21:18,470because the control is not parented to anything.
    00:21:21,821You can see if I move the control around now,
    00:21:23,464it will actually move that circle.
    00:21:26,329So if I rotate this around
    00:21:28,106and then move the control null,
    00:21:30,317the actual layer and the circle,
    00:21:32,527it moves with it.
    00:21:34,578However, if this control was parented to something else,
    00:21:39,215that wouldn't work.
    00:21:40,323And just to prove it, I'll make a null.
    00:21:43,218And I'm gonna move that null over here.
    00:21:45,178And now I'm gonna parent this control to it
    00:21:47,276and you'll see our layer move.
    00:21:49,162That is because when you parent something in After Effects,
    00:21:52,448and you may already know this,
    00:21:53,598but when you parent something in After Effects,
    00:21:55,246the position of that layer
    00:21:57,729changes to become relative to its parent.
    00:22:01,483So if I unparent this,
    00:22:03,071see how the position just snapped back?
    00:22:05,216That's because this position now,
    00:22:07,259since there's no parent,
    00:22:08,238is relative to the entire comp.
    00:22:10,385That's its true position.
    00:22:11,749But as soon as I parent it to this,
    00:22:13,608it's now
    00:22:14,977relative to this new null.
    00:22:16,762And that's not what we want.
    00:22:18,087So, you can do it this way.
    00:22:21,103But to be safer,
    00:22:23,010we can use one more expression.
    00:22:26,668So, I'm gonna highlight this
    00:22:29,388and I'm gonna replace it with,
    00:22:31,592I'm gonna pick whip
    00:22:33,066directly to this control layer.
    00:22:34,930Not to the position but actually to the layer itself.
    00:22:38,428And now we're gonna use an expression called toWorld.
    00:22:42,101And this expression,
    00:22:44,290it works, you basically select the layer that you want
    00:22:49,889and then you use the toWorld expression
    00:22:52,122and it will figure out that layer's true position
    00:22:55,881regardless of what it's parented to,
    00:22:59,206if it's rotated, anything like that.
    00:23:02,031So the way you use an expression like this,
    00:23:04,844is after this comp layer control,
    00:23:08,412so pointing to that layer,
    00:23:09,726I'm gonna hit period toWorld
    00:23:14,520and again, you could always look in here
    00:23:17,806if you click this little arrow,
    00:23:20,175you could look through here and you could probably
    00:23:24,738find the toWorld comp.
    00:23:26,150It may not make a ton of sense
    00:23:27,726and it's better off to just learn what toWorld does
    00:23:30,932and it's cousin to comp
    00:23:32,816and is gonna be again,
    00:23:34,630another great tutorial about both of those.
    00:23:36,800But the way toWorld works is you add toWorld parenthesis
    00:23:41,312and then you have to give it a,
    00:23:44,825you have to give it a coordinate,
    00:23:46,837and that coordinate is which point on this layer
    00:23:51,072is going to be the center.
    00:23:53,661And because we're using a null,
    00:23:57,044this control layer is a null,
    00:23:59,510nulls, the anchor point of that null is at zero zero zero.
    00:24:04,202On solids,
    00:24:05,655the anchor point's usually not at zero zero zero,
    00:24:07,974it's in the center of that layer.
    00:24:10,595So this solid is 200 by 200.
    00:24:13,069Its anchor point is actually 100 comma 100.
    00:24:16,065So if we were using the toWorld expression with that,
    00:24:20,067we would actually put in 100, 100, zero.
    00:24:23,768But we're using a null
    00:24:25,727and null's anchor points are at zero zero zero.
    00:24:29,209Okay, most of the time when you use toWorld,
    00:24:32,652you're gonna use zero zero zero.
    00:24:34,385But you just need to know what that number actually
    00:24:37,042is referring to.
    00:24:38,208So I'll put zero zero zero in here.
    00:24:42,082Close parenthesis and semicolon.
    00:24:45,181All right, so so far, nothing has changed.
    00:24:47,760This still works.
    00:24:48,593However, if I parent this to this new null now,
    00:24:52,450the layer doesn't move anymore.
    00:24:54,193It is still tied to the control null.
    00:24:56,883So this is just sort of future proofing it.
    00:24:58,998If you gave this rig to somebody to use,
    00:25:02,094and they parented this control null to another null
    00:25:05,450so they could get some kind of funky animation out of it,
    00:25:07,624it would screw everything up.
    00:25:09,856So this sort of protects against that.
    00:25:11,771And when you're writing expressions and making rigs,
    00:25:13,974that's really important.
    00:25:15,382All right, so I'm gonna delete this, this null up here
    00:25:17,745'cause we don't need it.
    00:25:19,083All right, so now what else do we need?
    00:25:23,447We are going to need a way
    00:25:28,161to have more than one layer in this carousel.
    00:25:32,802And so when I started building this rig,
    00:25:36,668I thought it would be cool
    00:25:38,696if there was a way to basically add layers
    00:25:42,597to the carousel
    00:25:43,881and have the carousel automatically position them
    00:25:45,966in the right spot.
    00:25:47,569And I knew that would be a little bit tricky.
    00:25:49,523But I figured there had to be a way to do it.
    00:25:51,619Because expressions are so powerful,
    00:25:53,830you can do almost anything you want.
    00:25:55,472You just have to be kind of creative with it.
    00:25:57,953So what I did was, I duplicated this layer,
    00:26:03,087so I have image_01,
    00:26:04,514and I'm gonna name this one image_02,
    00:26:06,427move it underneath.
    00:26:07,839And I thought to myself,
    00:26:09,477what would need to change on this image_02
    00:26:13,857to put it in the right spot?
    00:26:15,626I've already got,
    00:26:16,808if I hit u to reveal my
    00:26:19,786key framed properties and I look at this expression,
    00:26:23,235I said well if there was a way,
    00:26:26,179I could have this layer's angle be different
    00:26:30,787than image_01's angle.
    00:26:32,960And specifically what I would need to do
    00:26:35,046is figure out how many images there are.
    00:26:38,372So let's say there was three images.
    00:26:40,195Image_01, image_02, image_03.
    00:26:43,245After Effects would somehow need to know
    00:26:46,671how many images there are
    00:26:48,385and then divide a circle into that many parts
    00:26:53,641so there's three images I'd have to divide that circle
    00:26:56,303into three parts
    00:26:57,477and the first image would be at an angle,
    00:27:01,712then image_02 would be,
    00:27:03,757one third of the way around the circle
    00:27:06,980at the next angle,
    00:27:08,087image_03 would be another third,
    00:27:10,612and have After Effects do the math for me.
    00:27:13,604So in order for that to happen,
    00:27:16,176All of these layers need to know two things.
    00:27:20,179They need to know how many images are in the carousel
    00:27:25,176and they also need to know which spot they are
    00:27:28,473in the carousel.
    00:27:30,445So the first part wasn't that hard.
    00:27:34,939So in order to find out how many images there are,
    00:27:39,714I thought well maybe what I'll do is I'll make a rule.
    00:27:45,474All right, whoever uses this rig, this is the rule.
    00:27:48,921I'm gonna make a new null.
    00:27:51,335And I'm just gonna rename it with a bunch of dashes.
    00:27:54,976And I'm gonna lock it.
    00:27:56,986And you could even go as far as
    00:28:00,489adding a comment column to this.
    00:28:04,779And could unlock it and say nothing below this.
    00:28:10,822So what my thought process was is
    00:28:14,901if I know that
    00:28:18,549there's gonna be a control null,
    00:28:21,107everything underneath that is an image that's gonna be
    00:28:24,160used in the carousel.
    00:28:25,367I could put things above it
    00:28:27,183but everything below it is going to be an image.
    00:28:30,277Then all I need to do is find out what index
    00:28:33,645in the comp this control is,
    00:28:35,977and then have my layer subtract its own index
    00:28:40,822and then I'll be able to find out
    00:28:42,571what spot it is in the carousel,
    00:28:45,466and I could even subtract the index of the control
    00:28:48,420to find out how many images there are in the carousel.
    00:28:53,398As I just said that out loud,
    00:28:54,665I realized that probably made no sense.
    00:28:56,294But if you bear with me I promise it will
    00:28:58,149once we get going.
    00:28:59,974And I'll show you guys exactly what I'm talking about.
    00:29:02,859So, let's go into the position key frame
    00:29:06,860for image_01.
    00:29:08,097All right, so what I'm gonna do is I'm gonna go
    00:29:10,259to the top of this expression
    00:29:11,992and I'm going to hit enter a few times
    00:29:14,118so I can get some more space up top.
    00:29:16,204So I'm gonna make two variables.
    00:29:18,653I'm gonna make one for the number of layers in the carousel
    00:29:23,362and actually I'm gonna make first,
    00:29:25,592I'm gonna make a variable for the number of layers overall.
    00:29:28,812And then we're gonna use that number to figure out
    00:29:30,973how many layers are in the carousel.
    00:29:33,000Then I'm gonna make another variable where we're gonna
    00:29:35,734figure out which spot in the carousel each layer is.
    00:29:41,409So, I'm gonna make a variable called layerCount.
    00:29:46,136LayerCount on its own means nothing.
    00:29:49,401I have to tell After Effects what layerCount means.
    00:29:52,875And I had to look this up too.
    00:29:54,763I didn't know this existed.
    00:29:55,848But there's actually a property
    00:30:00,008of compositions in After Effects called num layers.
    00:30:04,974So if I type in this comp,
    00:30:08,478this is the way that After Effects refers to
    00:30:11,698the comp you are currently in.
    00:30:14,893And then the property is num layers.
    00:30:19,933And I should probably spell layers right
    00:30:21,504otherwise it won't work.
    00:30:24,268Okay, so now my variable layer count
    00:30:26,719is gonna return the number of layers in the comp
    00:30:29,535which currently is five, okay.
    00:30:32,516So keep that in mind.
    00:30:33,667Then I need to...
    00:30:37,525I need to know
    00:30:42,148which spot in the carousel this image is.
    00:30:46,060Now we know by looking at it that it's in the first spot.
    00:30:50,234But After Effects doesn't know that, it's not smart enough.
    00:30:53,236So what I need to do is subtract the number of layers, five,
    00:30:58,761from the index of the control null, okay.
    00:31:03,077And that will tell me the,
    00:31:05,883that will tell me the starting layer.
    00:31:09,442Because let's say we had a camera above this
    00:31:12,091or some lights or something like that.
    00:31:13,539All of these numbers would increase.
    00:31:15,215So the control null is always gonna be right above
    00:31:18,626the first image in the carousel.
    00:31:20,828So knowing that, I'm gonna make a new variable
    00:31:25,395and we are gonna call this objectCount.
    00:31:30,132And this is gonna tell us how many images are actually
    00:31:33,732in the carousel.
    00:31:37,027The number of layers in the carousel
    00:31:39,174is going to be the number of layers total in the comp
    00:31:42,388minus whatever index control is at.
    00:31:45,204Okay, we have five layers total.
    00:31:47,255Control is at index two.
    00:31:49,573That means if we subtract two from five,
    00:31:52,355five minus two is three.
    00:31:54,566And that is how we're gonna find out
    00:31:56,396that we have three images in the carousel, all right.
    00:31:59,147So it's gonna be layerCount minus the index of control.
    00:32:04,544And the way you get the index
    00:32:06,257and when I say index it's literally this number
    00:32:09,315right next to the layer.
    00:32:10,261That's the index.
    00:32:12,405I'm gonna pick whip the control null and put
    00:32:16,263.index with a semicolon.
    00:32:22,499And you're probably noticing a recurring theme here.
    00:32:25,780The way expressions work in general in After Effects
    00:32:29,465is you go from more general to more specific.
    00:32:33,891So every time you add a period to an expression,
    00:32:37,381you're getting more and more specific.
    00:32:39,000So you're starting with this comp
    00:32:41,170and then there's a period.
    00:32:43,217This comp layer control.
    00:32:45,334So in this comp there's a layer called control,
    00:32:47,650period, we're looking at that layer's index.
    00:32:50,535So, general to specific.
    00:32:53,219Now that we have a account of how many objects there are,
    00:32:56,804now we can find out the index of this specific image
    00:33:02,628in the carousel.
    00:33:04,395So that would be the number of objects,
    00:33:14,004the control null's index two.
    00:33:17,374And you'll see that that works.
    00:33:19,363This first image is index three.
    00:33:22,148So if I subtract two,
    00:33:24,672which is the index of the control,
    00:33:26,442that gives me one.
    00:33:27,572That means this is the first image
    00:33:30,449in the carousel.
    00:33:32,158If we did it with image_02 which has an index of four,
    00:33:36,024we subtract two from four,
    00:33:38,869that means this is the second spot in the carousel.
    00:33:42,164All right, so you can see that,
    00:33:44,817just by doing some really simple math,
    00:33:46,324we can actually figure out how many objects there are
    00:33:49,448and what object index each one is in the carousel.
    00:33:52,229So this object index is going to be
    00:33:54,916the index of this layer,
    00:33:57,814and when you are trying to find the property of the layer
    00:34:01,297that you're actually typing an expression into,
    00:34:04,220you don't have to type in this comp layer.
    00:34:06,842If you don't type that in,
    00:34:07,879it assumes you are referring to the current layer
    00:34:10,316you're working on.
    00:34:12,328So if I type in index,
    00:34:14,269it's gonna give me the index for this layer which is three.
    00:34:18,077And we need to subtract the index of control.
    00:34:23,860So I pick whipped control.
    00:34:25,297I'm gonna put period index.
    00:34:30,366All right, so now we have the information we need
    00:34:34,602to figure out how to divide that circle up
    00:34:38,428and place all of these
    00:34:40,820layers into the right spots.
    00:34:43,598All right.
    00:34:45,814So what I need to do is
    00:34:49,846figure out how to divide a circle
    00:34:52,007which is 360 degrees
    00:34:54,019into a few different pieces and place things
    00:34:57,238in the right spot.
    00:34:58,870All right, so the property
    00:35:01,003that we're gonna be changing here is angle.
    00:35:04,690So the first thing I want to do
    00:35:07,670is I need to separate out the angle from the controller
    00:35:12,206with the actual angle that this is gonna be placed at.
    00:35:16,314Because if our control is set to 180 degrees,
    00:35:21,815meaning I've spun the entire carousel 180 degrees,
    00:35:25,397image_03 is not gonna be at 180 degrees.
    00:35:28,250It might be at,
    00:35:30,306you know it might be at 270 degrees.
    00:35:32,143It's gonna be somewhere else.
    00:35:33,734So I want to separate those variables out.
    00:35:38,031So what I'm gonna do.
    00:35:39,189I'm just gonna stretch this out
    00:35:40,223so I can see a little better.
    00:35:42,373So this variable here, angle,
    00:35:45,121I'm gonna rename that
    00:35:50,654Because this is the angle coming right out of the control.
    00:35:53,894This is the raw angle.
    00:35:55,159But this is not actually the angle that I want to use.
    00:35:59,095So let's think about this for a second.
    00:36:01,148You have 360 degrees in a circle.
    00:36:04,174So we have three images here.
    00:36:07,862So if the
    00:36:10,150control is set
    00:36:13,226to zero,
    00:36:14,953then this first image can be at zero.
    00:36:19,390But the second image needs to be 1/3 of the way
    00:36:22,672around the circle.
    00:36:24,246So if I do a little math.
    00:36:27,249360 divided by three
    00:36:29,710is 120.
    00:36:30,863So the second image would be at 120.
    00:36:34,173The third image would be at 240.
    00:36:37,182So basically all we need to do
    00:36:39,835is divide 360 by the number of layers in this carousel
    00:36:45,734and then we just need to multiply that number,
    00:36:49,680whatever the distance is between layers.
    00:36:52,864We just need to multiply that
    00:36:55,178times the
    00:36:58,121place in the carousel
    00:37:00,041that each layer holds.
    00:37:01,939So let me type that in,
    00:37:02,972see if that makes any more sense than what I just said.
    00:37:06,428So what we need to calculate is an offset.
    00:37:09,350What is the offset?
    00:37:10,662Basically the spacing between layers.
    00:37:13,177All right, so I'm gonna make a new variable,
    00:37:14,685call it offset.
    00:37:15,874And this is going to be 360 degrees
    00:37:20,726divided by the objectCount.
    00:37:25,676So we have three objects, so the offset so far
    00:37:28,168is 360 degrees divided by three, 120.
    00:37:32,199However, this is the first image,
    00:37:34,171this is the second image.
    00:37:35,208They're all gonna have different offsets.
    00:37:37,469The first image is gonna have an offset of
    00:37:40,678you know 120
    00:37:41,688but then the next image has to be 240.
    00:37:44,552So what we need to do is take that offset,
    00:37:46,600we need to multiply it by the object index.
    00:37:50,757What is the spot this layer occupies in the carousel?
    00:37:57,942Cool, so if you think about what this is gonna do,
    00:38:01,845the first layer is going to be 360,
    00:38:05,125divided by three,
    00:38:07,716times one.
    00:38:08,738It's gonna be 120.
    00:38:10,453If this same expression's on the next one,
    00:38:12,599that will be at 240, not 120.
    00:38:16,060So by doing this, we're letting After Effects
    00:38:20,425do all the math for us.
    00:38:21,727And if I create more layers, in theory,
    00:38:24,373it should space them out evenly for us,
    00:38:25,887no matter how many we have.
    00:38:28,617All right, so...
    00:38:31,032The last step is
    00:38:34,283to actually calculate the real angle.
    00:38:39,565All right, so...
    00:38:41,854In order to do that,
    00:38:43,840I need to create a new angle variable.
    00:38:47,553So, the actual final angle of these layers
    00:38:51,469needs to be whatever this offset is now,
    00:38:54,710plus whatever the control angle is set to.
    00:38:57,766So that way we can still animate it.
    00:39:00,237So if the control was set to zero,
    00:39:05,623then After Effects would spread all of these layers around
    00:39:09,367and then as we animate it up to 180,
    00:39:12,273it's gonna add 180 to every offset of every layer
    00:39:15,469and it's gonna move them all in a circle together
    00:39:17,559in sync.
    00:39:19,575So this angle needs to be control angle
    00:39:25,086plus offset.
    00:39:29,632Okay, now if I've done this right (laughing)
    00:39:33,417this should work.
    00:39:34,759So I'm gonna hit Control + Enter.
    00:39:37,470Sorry, I'm gonna hit Enter.
    00:39:40,818You'll see that something,
    00:39:42,300I basically only have that expression
    00:39:44,143on this layer right now.
    00:39:46,260So I'm gonna hit u,
    00:39:47,672click position,
    00:39:49,161and if you go up to Edit,
    00:39:52,053you can copy expression only.
    00:39:54,229In this case you could also copy
    00:39:56,149because copy expression only is useful
    00:39:58,634because if you had key frames on position,
    00:40:01,858and the expressions were actually referencing
    00:40:04,322the key frames you had on there,
    00:40:05,709you could copy the expression
    00:40:07,120without copying the key frames.
    00:40:08,842And that can be pretty useful sometimes.
    00:40:10,582So I copy that expression
    00:40:12,068and I'm just gonna paste it
    00:40:14,037onto image_02 and image_03.
    00:40:15,838And let's see if this works now.
    00:40:18,545All right, so we have three layers
    00:40:22,520and they all seem to be spread out evenly.
    00:40:25,232Now to check that,
    00:40:27,025I'm gonna add camera.
    00:40:30,812Let's just do a 35 mm camera
    00:40:34,459and I'm gonna grab my camera rotate tool
    00:40:37,023and just kind of pan up here so we can see it.
    00:40:41,053All right, so I hope that all made sense.
    00:40:44,146This slider here
    00:40:47,223is feeding
    00:40:49,843the control angle variable in all of these.
    00:40:52,998So right now the control angle
    00:40:55,041is negative 55.
    00:40:58,134Then we've calculated the offset.
    00:41:00,268How far apart do each of these layers need to be?
    00:41:03,119There's three layers so they each need to be
    00:41:04,961120 degrees apart.
    00:41:07,316So the actual angle is gonna be negative 55 plus 120
    00:41:11,840and we're gonna take the 120 and multiply it times
    00:41:14,663one on this layer,
    00:41:16,103two on this layer,
    00:41:17,096and three on this layer.
    00:41:18,392And that's how we're getting this even distribution.
    00:41:21,143And what's great about this
    00:41:23,100is because if we duplicate these layers,
    00:41:27,218you can see that it doesn't matter how many layers we add.
    00:41:31,021After Effects is always gonna spread these out evenly
    00:41:35,223for us now.
    00:41:36,951All right, so we've got the beginnings of a
    00:41:38,821pretty cool rig here that will be very helpful.
    00:41:43,777So now, we have all these layers, I'm gonna
    00:41:47,850increase the radius.
    00:41:49,735And you see we've got all this control.
    00:41:51,147I can move the control null around.
    00:41:54,966I can slide this.
    00:41:56,541Now I knew early on that
    00:42:00,096once I built this,
    00:42:01,204I sort of moved the camera around,
    00:42:02,924I said well this is pretty great right here.
    00:42:04,702However, what if we have a camera that's moving around or
    00:42:07,627what if we want to use the carousel from the top down
    00:42:10,875like this?
    00:42:12,535I want to be able to control
    00:42:16,367where these layers are facing
    00:42:18,857so that we can sort of manually tweak that
    00:42:22,367to get the look we want
    00:42:23,894and get the angle we want.
    00:42:25,881So what I did was I started
    00:42:27,609with one of these layers, image_01.
    00:42:32,318And I opened up the rotation tab.
    00:42:34,907And I suspected this would be pretty simple.
    00:42:39,674But I wanted to see how these things would react.
    00:42:43,144Because we have a pretty complicated expression
    00:42:45,461on the position property.
    00:42:48,110But even with all of that going on,
    00:42:50,201you can still just grab the x, y, and z rotation, right.
    00:42:54,387So, in order to have that fine tuning control,
    00:42:58,259really all we need to do is create a control
    00:43:00,377for x, y, and z rotation
    00:43:02,696and have all of these images reference that same control.
    00:43:07,259So in my control null, I'm gonna make a new angle control
    00:43:12,947and we're gonna call this X_Offset,
    00:43:19,959and Z_Offset.
    00:43:25,872And I'm just going to,
    00:43:27,899I'm gonna hold Option
    00:43:29,502and click on x rotation.
    00:43:31,314You can see
    00:43:32,799I need to make sure that I have my effects opened up
    00:43:37,894on this control null,
    00:43:38,948otherwise as soon as I hit add an expression,
    00:43:42,961I didn't have anywhere to pick whip it to.
    00:43:45,585So I'm gonna open all these up.
    00:43:48,655All right so x rotation is gonna be tied to this.
    00:43:52,410This X_Offset,
    00:43:54,347y rotation is gonna be tied to the Y_Offset,
    00:43:57,738z rotation will be tied to Z_Offset,
    00:44:01,698and then I'm gonna copy
    00:44:05,598the expressions from image_01 that I just created
    00:44:09,428and I'm gonna paste them
    00:44:11,848onto all of these images.
    00:44:17,316And then,
    00:44:19,391now these controls should work.
    00:44:21,047So the X_Offset, rotates on the x axis,
    00:44:25,178y is on the y,
    00:44:26,980z is on the z, that's great.
    00:44:28,818So now if I take this camera
    00:44:32,683and move overhead,
    00:44:36,541and zoom out a little bit,
    00:44:38,729I can rotate these on the x to face me
    00:44:42,602and then rotate the carousel and they'll move in a circle
    00:44:45,123but they'll all face me.
    00:44:48,497So, so far we
    00:44:50,807pretty good shape here.
    00:44:52,268So, the last thing that I wanted to add to this rig,
    00:44:56,349which I thought would be really cool,
    00:44:58,856is an option to
    00:45:02,565have these layers face outward.
    00:45:06,998So face sort of in a tangent to the circle
    00:45:09,779instead of always facing the camera.
    00:45:12,613Using the carousel like this is pretty common.
    00:45:16,113And so this is probably most of the time
    00:45:18,271how you'd want to use it.
    00:45:19,451But you never know and
    00:45:20,732you could also use a setup like this to do some really cool
    00:45:23,165motion graphics things
    00:45:24,478without using icons or logos or whatever
    00:45:27,327you'd normally use this for.
    00:45:28,493You could create cool shapes and wheels
    00:45:30,449and things like that.
    00:45:31,904So I wanted that option and I wanted it to be
    00:45:33,605really simple to set up.
    00:45:37,223So, what I figured was I need to be able to rotate these,
    00:45:44,376basically control the y rotation of all of them.
    00:45:50,146Because the y axis runs up and down
    00:45:52,091and that's where you'd rotate
    00:45:53,429to turn those layers to face them outward.
    00:45:56,295So if I look at image_01, I hit r,
    00:45:59,252I realize that I still have my orientation property
    00:46:04,330that has no key frame on it.
    00:46:05,797So rather than try and do some funky math
    00:46:09,270with the y rotation that's being driven by this control,
    00:46:14,005where I'd have to kind of figure out
    00:46:16,466how do I adjust this but still have them face outward.
    00:46:19,797It would be kind of tricky.
    00:46:21,823I can use this orientation property.
    00:46:24,284And you'll see if I adjust the y orientation,
    00:46:28,891I can rotate this to face outward.
    00:46:31,348So that's what I needed to do.
    00:46:34,920So right now, my control angle is set to zero.
    00:46:39,443And I wanted to figure out
    00:46:43,456what number of degrees do I need to turn these images
    00:46:48,017to face outward instead of right at us.
    00:46:51,458And I'm gonna be turning them on the y axis
    00:46:54,178because you can see here's the y axis.
    00:46:56,540And if you turn it on that,
    00:46:57,951you can make them face outward, right,
    00:47:00,197just like that.
    00:47:01,536So I wanted to figure out what's the number of degrees
    00:47:03,621I need to turn this for it to face the correct direction.
    00:47:07,781And with the control angle set to zero,
    00:47:12,747it turned out that this needs to be about 270.
    00:47:18,636And that gave me a hint of how I was gonna set this up.
    00:47:25,072if you split the circle
    00:47:26,730into 90 degree sections,
    00:47:29,695you'll get
    00:47:32,334zero degrees,
    00:47:33,16790 degrees,
    00:47:34,073180 degrees,
    00:47:34,980and then 270 degrees.
    00:47:37,402So I said, oh that's interesting.
    00:47:39,513This solid over here appears to be facing
    00:47:42,732straight out to the right.
    00:47:44,943And it happens to be 270 degrees is the right angle
    00:47:48,716for it to face outward
    00:47:50,054instead of directly at me,
    00:47:52,286when my control angle's set to zero.
    00:47:54,085So it's a difference of 90 degrees.
    00:47:57,122So, I thought maybe all I need to do
    00:48:00,333is subtract 90 degrees from my control angle.
    00:48:05,716So that's what I tried.
    00:48:07,032I put an expression on orientation
    00:48:10,843and I said y equals,
    00:48:13,649because I'm gonna be messing with the y rotation,
    00:48:16,198I pointed it to the control angle
    00:48:18,224minus 90,
    00:48:21,223and then that little error message
    00:48:22,879that just came up,
    00:48:24,434that's telling me that,
    00:48:26,493this property orientation,
    00:48:28,034it's looking for three values,
    00:48:29,637x, y, and z.
    00:48:31,134So you actually need to give it three values,
    00:48:33,319even if you're only changing one of them.
    00:48:35,291The way you do that in After Effects
    00:48:36,729is you open some brackets,
    00:48:39,607and then we're gonna start with the x value,
    00:48:42,217which is always gonna be zero,
    00:48:44,691the y value is gonna be this y variable
    00:48:47,570we just calculated up here,
    00:48:49,031and then another comma and a zero for the z property.
    00:48:53,221Close the bracket, semicolon, and there we go.
    00:48:56,719So now this is facing the right way.
    00:48:59,755But when I turned the carousel you see that
    00:49:04,239it's spinning around kind of opposite
    00:49:07,355of the way it needs to go.
    00:49:10,683However, it is consistent,
    00:49:12,006so I thought well maybe then all I need to do is subtract
    00:49:16,283this control angle times negative one
    00:49:20,960and maybe that'll fix it.
    00:49:22,099So I just put a negative sign at the beginning
    00:49:25,211of this expression here.
    00:49:27,852And that fixed it.
    00:49:30,047So now you can see that one layer that has the expression
    00:49:33,611is facing outward, okay.
    00:49:35,942Now, I wanted to have an easy way
    00:49:38,534of turning that on and off.
    00:49:40,253And After Effects has this really cool
    00:49:43,140expression control.
    00:49:44,811So I'm gonna go to my control null
    00:49:45,962and I'm gonna add a
    00:49:48,887checkbox control,
    00:49:50,500which is basically just an on and off switch.
    00:49:52,863And I'm gonna call this face outward.
    00:49:56,747By default it's off.
    00:49:59,595And in order to make this work,
    00:50:10,689I'm gonna have to give it an if then statement.
    00:50:13,621All right.
    00:50:15,893So, the way you do this with a checkbox control,
    00:50:20,567so I'm gonna add a few more lines here.
    00:50:22,035So, to do an if then statement in After Effects,
    00:50:25,274this works like almost any other
    00:50:27,853programming language out there.
    00:50:29,406And I'm just gonna briefly go over it.
    00:50:31,250All you need to know is the syntax of making it work.
    00:50:35,022And then on your own
    00:50:35,958you should definitely play around with it
    00:50:37,289because you can get really crazy with controls
    00:50:40,326and creating a lot of automated things
    00:50:42,388with if then statements.
    00:50:44,176So the way it works is you type in if.
    00:50:46,391In parenthesis you type in
    00:50:48,220the thing you're testing, all right.
    00:50:51,470And what we're testing is,
    00:50:52,740is this checkbox on or off?
    00:50:54,696So I'm gonna pick whip directly to that checkbox
    00:50:59,042and actually that's all you need to do.
    00:51:03,164Technically a checkbox,
    00:51:05,480it either equals zero when it's off
    00:51:08,000or one when it's on.
    00:51:09,786That's how they return values.
    00:51:12,004But you don't have to type in
    00:51:16,155equals one.
    00:51:19,082If you do an if then statement and the only possible
    00:51:23,827options are zero or one
    00:51:26,266then if you just leave this,
    00:51:28,338if you just close the parenthesis here
    00:51:29,906and leave this in there,
    00:51:31,322then this will return a one if this is on,
    00:51:34,201and a zero if it's off.
    00:51:35,551So you don't even need to do any more than that.
    00:51:37,840If you wanted to,
    00:51:39,986you could come in here and type in equals one.
    00:51:43,816If this checkbox equals one,
    00:51:46,696and when you're testing things with if then statements,
    00:51:49,457you have to do double equals signs.
    00:51:51,043You can't do one equals sign, that won't work.
    00:51:53,961So we're testing, does this equal one, is it checked.
    00:51:58,646So then we're gonna do these curly brackets.
    00:52:02,849So we're going to open curly brackets
    00:52:04,317and this is how you tell After Effects,
    00:52:06,637I'm about to give you a series of things
    00:52:08,695that you only do if this is true.
    00:52:12,590And you can actually go into the next line
    00:52:14,670to start that.
    00:52:16,027So if this is true.
    00:52:17,902Let me open this up a little more
    00:52:19,608so we can see it better.
    00:52:23,813All right, so if this is true,
    00:52:25,884this is what I want to do, all right.
    00:52:28,866If it's checked, this is how I want you
    00:52:31,458to calculate the angle, all right.
    00:52:35,156So all you need to do is leave that as is.
    00:52:38,485Then underneath this you have to close the curly brackets.
    00:52:42,962Okay, and what happens if it's not checked?
    00:52:47,085Well, if it's not checked you want to do something else.
    00:52:50,607So, ironically, that's what you're gonna type in.
    00:52:53,649You're gonna type in else.
    00:52:55,285All right, so if this happens, do this.
    00:52:59,850Else, you know otherwise,
    00:53:02,268you're gonna open another set of little curly brackets,
    00:53:04,556go to another line.
    00:53:05,903If this is not checked I just want these all to be zero.
    00:53:11,108So I'm just gonna do a bracket,
    00:53:12,665zero, comma zero, comma zero,
    00:53:14,132close bracket, semicolon.
    00:53:16,156And then close the curly cue.
    00:53:19,043So you have two sets of instructions inside of
    00:53:21,661little curly cues.
    00:53:24,144One set gets executed if that's checked.
    00:53:27,061The other one gets executed if it's not checked.
    00:53:30,026And there you go.
    00:53:31,435So now if I check this,
    00:53:32,618you'll see that that turns that behavior on and off.
    00:53:36,447And so now,
    00:53:38,347I'm gonna copy that expression for orientation
    00:53:43,229onto all of these, okay.
    00:53:47,188And let's see if that worked.
    00:53:48,848So if we turn this on,
    00:53:51,867a-ha you'll see it didn't work.
    00:53:55,124That is because once again,
    00:53:58,926we are going to need After Effects to adjust that angle
    00:54:03,490based on the position in the circle.
    00:54:06,962So once again, we're going to have to
    00:54:10,139multiply that
    00:54:13,18590 degree offset
    00:54:14,526by the position
    00:54:17,749in the circle.
    00:54:20,312So, what we're gonna need to do is...
    00:54:23,740So let's just pick one of these images here.
    00:54:27,279I'm gonna hit u so I can see all of our expressions we have.
    00:54:31,556So the position expression has all of this stuff up here
    00:54:36,725that already sort of does the work for us
    00:54:38,684of figuring out
    00:54:41,325like how many layers there are
    00:54:44,458and then which sequence in the circle,
    00:54:46,619the layer exists in.
    00:54:48,811So I'm going to copy all of this stuff.
    00:54:53,673Basically everything from the layer count
    00:54:55,326down to the angle.
    00:54:56,433We don't need to have all of this math stuff down here
    00:54:59,533because all we're gonna be doing is rotating this.
    00:55:02,065We're not gonna be moving it all right.
    00:55:03,343So I'm gonna just copy all of this.
    00:55:07,169And then I'm gonna put it
    00:55:10,324at the top of this orientation
    00:55:13,305expression here.
    00:55:14,915I'm gonna paste it in.
    00:55:16,704So now this orientation expression
    00:55:18,589is getting pretty long.
    00:55:21,887Kind of scary looking.
    00:55:25,110So then what we need to do is
    00:55:27,989basically figure out
    00:55:31,013what is the property that needs to change
    00:55:34,986to make all these face outwards.
    00:55:36,381So we already know that
    00:55:38,516for one of these layers all we had to do was
    00:55:43,061subtract 90 from the inverse
    00:55:45,928of whatever the control angle was.
    00:55:48,780So what that means is that
    00:55:50,519if this one needs to be 90 to face the right way,
    00:55:55,102what does this one need to be?
    00:55:56,293Well it would need to be 90 plus
    00:55:59,822whatever the offset angle is.
    00:56:02,144Because we've already calculated,
    00:56:05,581we've already split this circle up into seven parts
    00:56:09,396'cause there's seven layers here.
    00:56:11,986And so we know that if one solid is facing the right way
    00:56:17,327at 90 degrees,
    00:56:18,308then the next one's gonna be 90 degrees plus
    00:56:22,224360 divided by seven, so.
    00:56:24,036We've already got this,
    00:56:27,050we've got the angle of that layer already calculated
    00:56:30,173right here.
    00:56:31,414And it's based on all of this work we did up here.
    00:56:34,494So what we need to do is
    00:56:39,747instead of using the control angle,
    00:56:42,914which is what this is,
    00:56:44,673we actually want to use the offset.
    00:56:47,523Or sorry, not the offset, the angle.
    00:56:49,711All right,
    00:56:50,612and I know this might be a little confusing.
    00:56:52,661Remember that we set up two variables.
    00:56:55,281The control angle, which is what the control null
    00:56:58,307is set to.
    00:56:59,297But then the actual angle,
    00:57:00,899which takes into account the position of each layer.
    00:57:05,116That's the angle that we want to
    00:57:06,483multiply times a negative one,
    00:57:08,328then subtract 90 from, okay.
    00:57:10,889And you can see already that
    00:57:13,812we were working on image_01 which is this
    00:57:15,582and now it is facing outward.
    00:57:17,137So now, I think this expression is correct.
    00:57:19,585So I'm gonna copy that expression
    00:57:23,920and paste it on all these one more time.
    00:57:26,632And now they all face outward.
    00:57:30,827So if we rotate this using the control null,
    00:57:34,935they all face outward.
    00:57:37,767And then if I turn this off,
    00:57:39,167they all face forward.
    00:57:42,406And there you go, there's your rig.
    00:57:46,999Just a last few minute housekeeping things that I did.
    00:57:51,216Right now, all of these are the same Precomp.
    00:57:54,442Even though we've named the layers different things,
    00:57:57,089you'll see if we click layer name
    00:57:58,386to show the source name instead,
    00:57:59,454they're all image_01.
    00:58:01,770So if I go in here
    00:58:04,225and I grab one of those icons,
    00:58:06,399like this little clock,
    00:58:08,783stick that in there.
    00:58:12,151Turn off the orange solid,
    00:58:14,225you'll see that they're all the same.
    00:58:16,612And that's obviously not what we want.
    00:58:18,226So what I did was I made a bunch of Precomps,
    00:58:24,532image 1-10.
    00:58:26,651And I just went through one by one
    00:58:29,573and replaced,
    00:58:35,547just like this.
    00:58:36,380I just replaced all the layers with their own Precomp.
    00:58:38,341So now, you could actually go in
    00:58:41,491and swap out any of these layers
    00:58:44,861with any image you want.
    00:58:46,417Currently these are set to 200 by 200 pixels
    00:58:48,892which is pretty small.
    00:58:50,261It's really only useful if you're just doing little icons.
    00:58:53,383But you could definitely scale these up.
    00:58:55,904It's not gonna affect anything.
    00:58:57,330This expression will work regardless of
    00:58:59,575how big these layers are.
    00:59:02,761You may have to increase the radius if you need to.
    00:59:07,533And that's about it.
    00:59:09,119So I am going to post this rig up for you guys
    00:59:13,351and I'll clean it up a little bit before I do that.
    00:59:15,525I'm also gonna post all of these icons for you
    00:59:19,024zipped up.
    00:59:19,995So if you want you can try to,
    00:59:21,462you can mess around with it and
    00:59:24,206all of these properties are key-frameable.
    00:59:27,531In the little demo I did at the beginning of this video,
    00:59:30,367I had to key frame some of those things
    00:59:32,008'cause the camera was moving around.
    00:59:34,473One last thing I want to show you guys
    00:59:37,265which I actually did
    00:59:38,998to make this even simpler to use,
    00:59:43,241is I created a remote control for this rig.
    00:59:46,509And I'll show you why that's cool.
    00:59:49,112So if we have this comp here,
    00:59:51,633which is called Carousel_tut,
    00:59:53,915and we bring it into a new comp, all right.
    00:59:58,067So as it is, this is
    01:00:01,605just a static layer, right?
    01:00:03,924If I add a camera to the scene
    01:00:09,067and I move it around,
    01:00:11,999you'll see nothing happens.
    01:00:13,742But if I hit this sunburst looking button here,
    01:00:17,835which is the collapse transformations button,
    01:00:20,321this is now back to a true 3D layer.
    01:00:24,928However, it's all contained in this one Precomp.
    01:00:28,788And the reason that is useful is because now
    01:00:32,977you can apply effects to this whole setup in one go.
    01:00:37,228So if you wanted to tint this
    01:00:41,733and give it like a purple tint or something,
    01:00:44,209you could do that to this Precomp
    01:00:46,887and then still move a camera around
    01:00:49,883and have this 3D comp.
    01:00:52,489And then what I did in the demo,
    01:00:53,998which is just a cheap trick that I'm ashamed of,
    01:00:58,031you can duplicate this comp.
    01:01:00,380Take one of them, name it reflection.
    01:01:06,927Scale it negative 100
    01:01:10,788on the y axis
    01:01:12,804and then move it down a little bit
    01:01:14,970so it's underneath.
    01:01:17,630And then just turn the transparency way down.
    01:01:21,354And now you have the poor man's reflection.
    01:01:25,011Reflective floor.
    01:01:27,745And Apple did this a decade ago
    01:01:30,334and ruined it for everybody.
    01:01:32,293But you know, you could even blur this a little bit
    01:01:35,216if you want to get really fancy, right.
    01:01:38,972So now the problem is that even though this is cool,
    01:01:44,000you would have to go into this Precomp to control
    01:01:46,832the actual rotation and all that stuff.
    01:01:48,621And that's gonna be really annoying.
    01:01:50,867So here's what I did.
    01:01:53,513I'm going to copy this control null
    01:01:57,051and I'm gonna bring it into this Precomp
    01:01:58,466and paste it.
    01:01:59,575And I'm gonna rename it remote.
    01:02:01,894Now wouldn't it be great if these sliders
    01:02:04,615could actually control the sliders
    01:02:06,930inside of this Precomp?
    01:02:09,039Well actually you can do that.
    01:02:11,604And here's how you do that.
    01:02:12,437So you need to have both comps open which we do.
    01:02:15,486We have Carousel_tut2,
    01:02:17,507which I'm gonna rename Master, it's clearer.
    01:02:20,854So we have Master and then we have
    01:02:22,556our carousel Precomp here, okay.
    01:02:24,875And what you can do is click.
    01:02:26,742You need to have them both visible and open at the same time
    01:02:29,491so if you click these little dots on the edge of the tab,
    01:02:34,256click and drag,
    01:02:35,089you can now drag this composition window down
    01:02:38,259and put it underneath the Precomp composition.
    01:02:42,234Now you have two comp windows open at the same time.
    01:02:45,402And I'm going to stretch this out
    01:02:47,027so we can get a little screen real estate here.
    01:02:50,702All right, so here's the actual controls.
    01:02:52,813So, if I hit e,
    01:02:54,558and I can open all of these up so we can see
    01:02:57,352all of the sliders.
    01:02:58,935And now here's our remote.
    01:03:00,680And I'm gonna hit e.
    01:03:03,790So I basically want all of these values to be driven
    01:03:07,272by these values.
    01:03:08,785And it's really as easy as just Option clicking
    01:03:11,878and pick whipping.
    01:03:14,067One by one, just like that.
    01:03:19,971And by the way, you can do this technique
    01:03:25,054with any property
    01:03:28,298in After Effects.
    01:03:29,686And this is also pretty useful if you have a camera
    01:03:33,956in this comp
    01:03:35,625and also a camera in this comp
    01:03:36,962and you want them to be in sync with each other,
    01:03:39,209you can do this with the position rotation
    01:03:41,269of the cameras too.
    01:03:43,083So anyway, so let me close this now
    01:03:46,641and let's put this back.
    01:03:49,361So now,
    01:03:52,210this remote control null
    01:03:54,703will actually control
    01:03:58,533these layers which are inside of a Precomp.
    01:04:01,861And so now this is really comically simple to animate.
    01:04:07,775And all of these things work,
    01:04:09,231even the face outward checkbox works.
    01:04:13,284So you're really, you're all set.
    01:04:15,361Now you can do whatever you want with this.
    01:04:17,420And let's say all of a sudden you need to add
    01:04:20,070one more icon.
    01:04:21,163All you gotta do
    01:04:23,727is come in here
    01:04:25,684and just add one more
    01:04:27,025and it will automatically update
    01:04:29,069and space out and work perfectly.
    01:04:31,962Thank you guys so much and look forward to next time.
    01:04:35,675Thanks for watching.
    01:04:36,728I hope you learned a ton about expressions
    01:04:38,911and how to use them to build a really useful
    01:04:40,734and reusable rig
    01:04:42,455like this carousel.
    01:04:43,820If you have any questions or thoughts,
    01:04:45,335let us know and we'd love to hear from you
    01:04:47,552if you used this on a project.
    01:04:49,394So give us a shout on Twitter
    01:04:50,806at School of Motion and show us what you've done.
    01:04:53,279Thanks again, and I'll see you next time.
    01:04:55,957(bouncing and whooshing)
    01:04:58,782(upbeat techno music)