Intro to After Effects Expression

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
- Hey, there. Joey here for School of Motion, and in this lesson, we'll be taking a look at the basics of Expressions and After Effects. If you've never used Expressions before, or even if you have, but maybe need a little refresher, this lesson will get you going in the right direction. We'll check out what Expressions are, how to use them, and why as a MoGraph artist, you need to know about them. Don't forget to sign up for a free student account, so you can grab the project files and Expressions from this lesson, as well as assets from any other lesson on the site. And now, let's jump in. - [Narrator] So if you look at this comp here, you'll see that I've set up a really, really simple scene, with a background and a clock, and I've already done the PhotoShop work of separating out the hour and minute hands of the clock. And I've also set the anchor point appropriately to the center of rotation of the two hands. So if I route the minute hand, you'll see that it rotates exactly as it should. So if you were asked to animate a scene that had a clock in it, there's an easy way to do it, but there's some pitfalls with that easy way, and I'm gonna show you that right now. So obviously, the easiest way would be to set a key frame on the rotation property at the beginning. So let's do that. And then to go forward in the comp, and change the values. So now you have two key frames, alright? So you can see that this works. However, let's say that you want a very exact speed for the amount of rotation of the minute hand. Let's say that you want one rotation every two and a half seconds, or something like that. Well, now it gets a little bit trickier. Because now you have to say, okay, well how long is my comp? Well this comp is two minutes long. If I'm having one rotation every two and a half seconds then what does this value need to be? And you have to do math, and no one likes to do math. So when you're using key frames, it's good if you're doing short, little bursts of animation. But when you're doing things like this, where you need a constant motion throughout the length of your comp, Expressions are a much better way to do it. So I'm just gonna use this as an example of how to apply an Expression, and sort of how you can work with Expressions and After Effects. So let's get rid of this key frame, and let's zero this back out. So the first thing we wanna do is actually enable an Expression on this layer, alright? And Expressions are applied to key frame-able properties like position, scale, rotation, transparency, or if you had an effect on this layer, you could apply Expressions to the properties of the effect. You can use them a lot of ways. One way you can apply an Expression is to click on the property that you want to add the Expression to, go to the animation menu and hit add Expression. I'm a big fan of hotkeys, and whenever possible I'm gonna try and teach you guys some really useful hotkeys because if you're trying to freelance, or impress your employer, or get a job, one of the best things that you can do as a Motion Graphics artist is get quicker, and be able to work faster and build things faster, and hot keys are probably the number one way to do that because when you get the hang of them, you'll find that you start doing them without even thinking about it, and you can work almost as fast as you can think. And that's really important. So the way I add Expressions is I hold the Option key, and by the way, I'm on a Mac. On a PC, I would imagine that's the ALT key. So you hold Option, and you click Rotation, and now we've enabled an Expression for that. You can see the value of Rotation turned red, and we've got this box over here where we can type our Expression. Now, the fastest way to use Expressions is to kinda learn the four, five or six that you use most often, and just kinda memorize them. And it's not as hard as it sounds, after you've used an Expression two or three times, you'll probably remember it. But if you forget, or if you're just new to Expressions, and you're not even sure what Expressions are out there, this little arrow can be your buddy because you can click this arrow, and After Effects has a built-in dictionary of all of the different Expression variables and functions that you can use, and it even gives you hints about how to use them. You'll see some of these functions have extra kind of options that are inside of parenthesis, and that tells you that if you use, for example, this random function which returns a random number, you need to need add a parenthesis, and put the minimum value, or array, comma, and then the maximum value, or array. So you may not totally understand that yet at this point, but just bare with me, this will all make sense. Just know that once you start using Expressions if you suspect that an Expression exists to do what you want, you can look through this menu, and you might just find it. So what we wanna do is find a way to have the rotation increase at a constant rate throughout the comp, alright? Now the best trick I know to do that is to tie the rotation to something that's already naturally moving, increasing at a constant rate, and that would be the time of the comp, alright? And you can find the variable for the comp time in the Global section here, it's just Time, or we can type it in. This one's pretty easy to remember, so we type in Time, and a good habit to get into is adding a semi-colon at the end of all of your Expressions. If you have a one-line Expression like Time, you technically don't need to use the semi-colon, but once you get into multi-line Expressions, After Effects will require every line to have a semi-colon, otherwise it sorta doesn't know where one line ends and the next one begins. When you're editing your Expressions to commit them, on the Mac you can hold Command and hit Return, or you can hit the Return that's on the number pad, and on a PC, it would be whatever the equivalent keystroke is for Command, it's probably CTRL. So now as we scrub through this, you'll see that the minute hand is moving at a constant speed. It's moving very slowly, but it's moving at the same speed the entire length of the comp, and this is great because if all of the sudden I needed to make this comp ten minutes long, I wouldn't have to change anything, it would still be animating at that same speed. Now the reason it's going so slow is because this time variable, it returns the comp time in seconds. So if we go to five seconds, for example, you'll see that the rotation is set to five. And the reason that I know this is because I have used the Expression Reference many, many times and this is where you wanna go if you wanna use an Expression, but you're not sure how. There's actually pretty good documentation for it. And there's also some great websites out there that will help you learn to do this stuff, and there's a lot great pre-built Expressions that people have put out there for free, and you can use them, and they're very helpful. And I'll put some links to those in this blog post. So back to our Expression, time is not doing it for us. It's making the minute hand move too slowly. So with Expressions, you can do simple math very easily. So what if we took that value, Time, and we multiplied by a number to increase the rate at which the minute hand's turning? So let's say that we wanted the minute hand to make one complete rotation every three seconds. So what that means is we would need it to turn 360 degrees in three seconds. So hopefully, you can do simple math because it is helpful. So if you divide 360 into three seconds, it's 120 degree per second. So every second, we want to multiply whatever Time it is, times 120. To multiply things in After Effects, you use the asterisk. When you're doing math, you use the plus sign, the minus sign, the asterisk for multiplication, and a forward slash for division. And those are the four operators that you'll use most the time. So if we type in Time times 120, hold Command and hit Return, you'll see now that minute hand is moving much faster. And you can see every three seconds, if we go to three. We have had one rotation in three seconds, alright? So now let's focus on the hour hand. So for the hour hand, I'm gonna hit R to open up the rotation properties, I'm gonna hold Option, click Rotation to add an Expression. So now the hour hand, we need the same idea, we just need it to move slower. So let's type in Time times. So now you just gotta kinda use a little bit of logic here, if the minute hand rotates once around this, how far does the hour hand go? Well it goes from one number to the next, right? So there's twelve numbers, so that means basically divide that circle into twelve pieces, right? So really I just need to divide this number, 120, by twelve. So that's how far it'll move, so 120 divided by twelve is ten. That's pretty easy. And so now, you can see here, we're at nine o' clock, and that minute hand's gonna go all the way around, and now we're at ten o' clock, alright? So we now have set up an accurately functioning clock, with no key frames, this clock could go as long as we make this comp. We can make this an hour, and this clock would just keep running indefinitely, and it would always tell the right time which is great. This is just a quick example of how Expressions can be useful and can save you a lot of time. If you had to key frame this, it would be a pain. And before we end the tutorial, I wanna show you one other quick thing about Expressions that's probably my favorite thing about Expressions. And this is the ability to set up controls for things like this. I'll show you what I mean by that. So what I'm gonna do is I'm gonna add a Null Object, right? And if you don't use Null Objects, you should get into the habit of using them. They are just objects in After Effects that have no image associated with them. They don't look like anything, but they're sort of like a utility layer, and you can use them to parent things. I can get into this in a later tutorial, but a lotta times they would be used, for example, to parent the minute hand, hour hand, and clock, to a Null, so then now you can move the Null, and it moves the entire clock. So you don't have to move all three layers. But what I'm gonna use it for here is to add some controls for the clock. So what I'm gonna do is rename this, Controls, and what I wanna be able to control is the speed that the clock is turning. And I wanna be able to control the minute hand and the hour hand with one control. So with Expressions, this is pretty easy. If you go up to the Effect menu, you'll see this Expressions Controls area, and if you never used Expressions, you've probably never used these controls. They are effects that on their own, don't do anything, but you can use them to drive other layers and other properties. So what I'm gonna do is pick the Slider Control, and you can go through and try out all of these controls, and you'll be able to see what they look like, and it may give you an idea of what they could control for you. The Slider Control just gives you one value that you can change, and you can slide it, or you can type in a number. And this doesn't do anything on its own, however it could drive something else. So let's rename this Slider Control, Clock Speed. So now if we open up this layer, go to Effects and go to Clock Speed, and the hot key for that would be E, and E brings up any Effects that are on a layer. And we open up this arrow here, so we can see the slider, and the reason we need to do that is because we are actually going to link the speed of the minute hand to this slider. So I'm gonna click the minute hand layer, and I'm gonna hit U. U is probably the most used hotkey in After Effects, you should definitely know that one. It opens up any key frame or properties that have Expressions on them. So we can see our Expression on here, and it says Time times 120, so instead of hard coding the number 120 into this Expression, I want this control to actually set what number we're multiplying times by. So what I'm gonna do is erase this, and we're now gonna use the PickWhip button here. This PickWhip button looks exactly like the one in the parent column, and it works the same way. The parent column let's you parent this layer to this layer by just picking it and letting go. So what we're gonna do is say we wanna multiply Time times, make sure you use this PickWhip in the Expression area, and we're gonna PickWhip it to this slider. And it doesn't work if you try to connect it to the Effect itself, it has to be to the value within that Effect. And you can see that After Effects automatically typed all this stuff in, and this is basically saying Time times this comp, meaning this Composition that we're in, the layer named, Controls, the Effect named Clock Speed Slider. So you can see, it basically just starts very wide. The entire comp, and it gets narrower, and narrower, and narrower until it's literally pointing to this exact Slider, in this Effect, on this layer. This is the way After Effects writes out the address of this, if you will. So we're gonna add the semi-colon, hold Command and hit Return, and the Slider's set to zero right now, but let's say I set that back to 120. So now the minute hand is moving again at exactly one rotation every three seconds. But if I change this to say, ten, now it's moving very slowly. See? So now, what's great about this is I can basically copy this Expression, I can just click in the box, and hit Command-C, or CTRL-C on PC. I'm gonna hit U on the hour hand. I'm gonna erase this Expression and paste the other Expression in there. Now, we don't want the hour hand to move the exact same speed as the minute hand, obviously. We've decided we need it to move twelve times less than the minute hand. So, what we're gonna do is have this Expression say Time times, all of this stuff, basically pointing to this Slider value, and then we're going to divide by twelve. So you can see you can have multiplication and then division, and you can basically type in a long string that will sort of do all this math for you, and arrive at the value, and give you what you want. So Command-Enter, and now you can see that the hour hand is moving at the right speed. So here we are at twelve o' clock, then the hand goes all the way around, now we're at one o' clock. Two o'clock. And the great thing is that now, if we want the clock to go faster, all we have to do is set this number to something else. If we wanted it to go faster, we could say 200, and it will go faster, but it will still work the amount that the hour hand moves relative to the minute hand will always stay correct because we've set up the Expressions to do that for us automatically. So this is a very small example of the power of Expressions, but hopefully, it'll get your brain thinking a little bit about ways to speed up your work by using this. Again, if you were gonna key frame this and have it be precise, it would be pretty tricky, and then if your client came to you and said, "Yeah, the clock looks great, but can it go about 15% faster?" Well that would be really tricky if you had key frames, and you'd have to do some math, and you'd have to do some trial and error. And with this, all you would have to do is change this number, change it to something else, and now the clock goes slower or faster, however you want it to work. So that was the introduction to Expressions. Hopefully, now you know how to apply Expressions, you know how to look for Expressions in the dictionary, and you know that you can always go up to Help, and hit Expression Reference and read about the Expressions there. And I hope moving forward, this provides a foundation you need to start using Expressions and After Effects. Thank you guys so much, and I will see you guys soon. - Thanks for watching. I hope you learned a ton from this lesson, and that you're now way more comfortable with Expressions than when you started. If you have any questions or thoughts, let us know, and we would love to hear from you if you use Expressions on a project. So give us a shout on Twitter, @SchoolOfMotion and show us your work. And if you've learned something valuable from this video, please share it around. It really helps us spread the word about School of Motion, and we truly, truly appreciate it. Don't forget to sign up for a free student account to access project files from the lesson you just watched, plus a whole bunch of other awesome stuff. Thanks again, and I'll see you next time.
Info
Channel: School of Motion
Views: 159,764
Rating: undefined out of 5
Keywords: motion graphics, tutorial, After Effects, Expressions, Intro, Basics, Tutorial
Id: cRASEWvhItg
Channel Id: undefined
Length: 19min 20sec (1160 seconds)
Published: Mon Jun 26 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.