Intro to Expression Rigs in After Effects

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
after effects rigs like this one are built using expressions this tutorial comes from our advanced motion methods course and in it noel honig and zach lovett will teach you how to use expressions to build flexible rigs plus some more advanced tricks you can start using right away let's keep going i know you're all really eager to get going so let's jump right into after effects i do want to jump in and talk about expression controls which some of you might know about but others might not and they will definitely help out when dealing with the big rig that we've set up for the end of this tutorial okay and also expression controls are awesome i love them they're really great for people like me who aren't necessarily really good at coding because they allow you to just kind of click and drag and you know the code is written for you essentially so it's a lot easier in many cases right so let's talk about expression controls [Music] what i've done here is i've set up a little comp with an orange square and a blue square and a controller which i've made a guide layer that is just a null object okay so if i select this and i go up to effect you see that there are all these expression controls up here you've probably played around with some of these the ones that i want to talk about today which i find most useful in my own workflow though i use all of them i'm going to talk about angle control checkbox control and slider control okay let's start with angle control i think that's the easiest to comprehend right on so when i click this on i get this kind of familiar looking angle control right and i can call this like square rotation or whatever just make it easier to understand what this is for okay so now obviously if i want to link actually i lie i'm going to take this and i'm going to lock it up here so that this effect control panel stays there okay so i'm going to take these and i'm going to press r to reveal the rotation property and it's very simple to affect these squares rotation using this angle control okay all i would have to do is option or alt if you're on a pc click on the rotation and then pick whip up here to the angle control i think you all know how to do this probably but just in case it's not clear now when i roll this angle control this square rotates right and i can do the same thing for the blue square um i can option or i'll click on this and now move over to this angle control and now both will work through this one control okay but actually what i want to do in this exercise is show how i can set things up for example so that the squares rotate in opposite directions which is slightly more complicated but not actually that hard because in this case all i would have to do is just choose one of the squares or the other and then get in here in the code and then just type times negative one okay and now i believe they would twirl oppositely yes which is really fun and cool and just in case it isn't totally clear let me just explain the math that's going on underneath the hood here okay so if i set my square rotation to 61 for example and down here my orange squares rotation is at 61 as you'd expect and the blue square is at negative 61. and the reason why that is is because of this code in here in which i have multiplied it by negative one okay it takes all the values from the control and makes them essentially the same but just negative right so that's how that works mathematically and i just want to say i'm sure this is obvious to all of you but at the heart of using expressions and slider controls is what's known as rigging in after effects okay which is to say that you create a situation where one layer pretty much controls the animation for a ton of other layers okay so let's take this to the next level and add a slider control here onto the control okay so i'm going to go up to effect expression controls and slider control and i'm going to call this my scale slider and for obvious reasons which is that i'm going to use it to affect the scale of these two squares so let me choose these two and press s okay to reveal the scale property now when dealing with scale you have two dimensions as you know i believe because scale is written as the x and y scale or the horizontal and vertical scaling of this even if you uncheck this you can't separate the dimensions like you can with position okay so we're going to need to use a little bit more uh coding to get this right okay so here we go i'm going to alter options click on the stopwatch to make my expression now i'm going to define some variables [Music] so let me first just explain what a variable is really quickly because it's actually a super important thing to understand about after effects expressions so technically a variable is anything in the code that can vary which is totally not helpful so let me explain it this other way all right technically a variable can be thought of as a named container that holds data hopefully that's a little bit clearer in terms of what i'm talking about but you know let me just say that the main advantage for using variables is that a human being can read them easily if they happen to look at your code okay so this is one big advantage is that if you define your variables well it's very clear what those variables are as opposed to just pick whipping to a whole bunch of stuff and not defining variables okay so that's one thing is that they can be read easily by people the other thing about variables that's great is that they can change okay so just say i define a variable as varex and i should mention by the way that in the code variables get shortened down to ver or var which some people pronounce var but i pronounce ver okay so just say i define varex okay what i could do is i could set varex to just equal 50 for example and then that would never change that value would just hold at 50 but what's much more useful and much more common is if i say varex equals and then i pick whip to just say a slider control and then that variable is dependent on the slider control value okay so i'm putting data into a container that can then change so i'm going to call varex which is you know what i'm going to use to deal with the x position and x scale values here okay where x equals and now i'm going to pick whip to this not this but this which is the x scale value okay and you can see here with the bracket 0 bracket that that means it's dealing with the first dimension which in this case is the x it often is in after effects okay now i'm going to say plus and i'm going to pick whip to the slider control okay now i'm going to put a semicolon and if you're new to expressions let me just point out that you should probably always end every sentence or thought with a semicolon in your code okay not always but generally speaking this is the way to go um so for example if you define varex as whatever you should put a semicolon in before going on to define the next variable like vare y for example go into the next line var y equals okay and now i'm going to pick whip to this plus and now i'm going to pick whip to this it's so easy with all this pick whipping i'm telling you okay and whoops just type a semicolon there and just to reiterate this one refers to so the zero refers to the first dimension of scale x and this one refers to the second dimension which is the y okay hopefully that's totally clear i'm sure it is now i'm going to just say bracket x comma y bracket okay and that should oops except for i typed ver instead of air that would have tripped me up all right so i'm going to type that over great so now this works just fine as i slide this up that gets bigger and as i slide that down that gets smaller okay so what i'm going to do is i'm going to right click on scale here and copy expression only and now i'm going to command v paste that right here okay so now you see when i slide this up they both get bigger and when i slide this down they both get smaller okay which is not what i want what i want is the opposite direction thing that we talked about before so in this case let's look at this code a second i'm going to press e to reveal my code and this is really simple all i have to do is get in here and take the pluses and make them into minuses and i believe that that should now yep and i kind of like this animation the way they sort of seem to be connected at the corner there right so that's really cool that's a cool little rig and you could always like animate this and this at the same time and that would be maybe a dynamic animation for you [Music] okay finally let's talk about checkbox controls and i want to teach you quickly about the if else expression which is super useful and work well together okay so i'm going to use it on the opacity of these layers so i'm going to choose t for my opacity i'm going to choose my controller and go up here to expression controls check box control okay this gives you this little check here which by the way for after effects when it's checked on it equals one and when it's checked off it equals zero basically so that's the value assigned to the check okay which is pretty useful so what i'm going to do is i'm going to get in here and i'm going to option click on this and i'm first going to define a variable of my checkbox versi equals this or whatever right okay good enough semicolon now i'm going to do the if else expression this is not that complicated i'm going to say if now remember i've defined c as that checkbox so i'm going to say if if that checkbox is greater than zero okay which basically means if it's checked okay because you remember checked equals one unchecked equals zero okay i'm gonna use some curly brackets here and i'm gonna say 100 and then close the curly bracket whoops that's a regular bracket okay now i'm gonna write else okay and i'm gonna go here and type another curly bracket and now i'm gonna say zero okay and i'm gonna go down here and i'm gonna close out that curly bracket great so what this means now is okay variable c is the checkbox if the checkbox is checked the opacity should be a hundred otherwise it should be zero right now and right now it's checked okay so it's on all right and if i uncheck this it's off okay so that's all that that does that's pretty much it and what i could do is uh right click and copy expression only and paste this onto the blue and now obviously they're both they'll both turn off when checked but if i want to do this the opposite for example here all i would need to do is take the greater than and make that equals equals which in javascript code equals equals okay so now if it's equal 0 which means that it's checked off now that's on right okay so that's cool that's how i would do that with the checkbox and that's an overview of if else expressions [Music] so wiggle is probably the most common expression for everyday motion designers in after effects it's this handy little function that lets you add a little bit of random movement to anything you'd like for our purposes we're going to look at only two components of wiggle and amplitude frequency means how often should we generate a new number so that's how many times a second do we want to change the value that we're looking at amplitude the second value is how much do we want this value to change on position that's like what is the maximum number of pixels that our layer should move to for rotation what is the maximum number of degrees it should spin to and so on using just these two parameters we can get a ton of control over just how random a property gets both in terms of amplitude the amount and frequency the speed [Music] let's take a look at what this means here i have a simple circle moving around with wiggle displaying a path behind it so you can easily see what it's doing if we jump into the graph editor and enable show post expression graph using this button you can see the results of your expression right in the graph editor you can see that there's a lot of movement here we're generating a new value 10 times a second so this is a pretty jittery graph let's change the first parameter frequency from 10 changes per second down to 2 and see what happens as you can see the graph is a lot smoother there's one fifth the animation going on here so the movement is a lot less frantic if we change the second parameter amplitude we're going to get this exact same pattern of movement but the values will now stretch to fit the new amplitude let's look at this in practice first a simple circle with the wiggle on the position with the frequency of 2 and amplitude of 400 we're telling the circle move to a new position within 400 pixels twice a second if we change the frequency you can see the animation is a lot slower the same applies for size we can randomize the circle's dimensions with the wiggle as well almost any property can be wiggled including things like color now if you're just typing in numbers once and never changing them this is a fine way to do it the issue is that if you want to change these values a lot or you want to add math or do other things with them it's kind of hard to do just in the space these little brackets one way to improve this is to move these values out to variables this way you separate the intention of defining the values of these properties and putting the values to use this has the huge benefit of letting us change them quickly easily and even do things like adding math or pick whipping them to other values here i can pick our amplitude to opacity which means that as a layer fades in and out the layer will wiggle more or less based on that number let's take this a step further what if you wanted to set up a whole bunch of different wiggles all with the same frequency and amplitude but then you wanted to go in and change those values now you could just duplicate your layer a bunch of times and you'll get different wiggles you can go in and you can edit your frequency edit your amplitude on each one but the issue is that this is a lot of work and if you have a ton of layers that's going to be really annoying so another way to do this is instead of having the values right in your expression you can have those variables set from expression control sliders by simply creating some sliders and using the pick whip you can now have your wiggle controlled by a different layer sliders which makes it even easier to change update those values or apply them to a ton of layers this works just the same way as if you were typing the numbers yourself except now you get these little sliders which makes it so much easier to use plus this has the benefit of being able to duplicate your layer a whole bunch of times and all of your child layers will now respect those same slider values so you can now change the frequency and amplitude of all of those layers at the same time without touching the expression ever again [Music] this section is called learning to learn the idea is that while we can't tell you everything about expressions we want to leave you with a few tips and tricks that'll help you debug or troubleshoot things that you're seeing in your own work first i want to show you the expression flyout menu now when you enable expression you get these little buttons here the first will toggle your expression on or off the second will be the post expression graph which we went over and wiggle and i'll go over in a bit more detail shortly third is the pick whip and the fourth is where the magic happens the expression language menu now when you click on this you're going to see a whole bunch of categories and each one contains a whole bunch of other things what these are are little code snippets or reference points they're sort of like building blocks this menu is the lego bin of components for how to build expressions now with the stuff you're seeing here sometimes you can use them exactly as is you can click on it and it's good to go other ones take some work or manipulation and they're just there as a placeholder but knowing that this exists and that things are broken up into these categories can make it a little bit easier to write expressions if you're not sure where you're coming from or if you're seeing an expression that somebody else wrote you can come in here and sort of see how it's meant to be used if it's a native after effects function now i'm going to start by adding a wiggle expression from this menu it's under property as these things can be applied to almost every property in after effects i'm going to choose wiggle you see here that it says freck or frequency amplitude octaves multiplier and time i don't really care i'm just going to click and see what happens now it's inserted that expression exactly as it was in the menu into our expression field but we're getting an error the problem is that frequency is not defined we know that we have to put numbers into these sections and yet it's giving us an error because there aren't numbers as mentioned this is more of a template for you to work with but frequency we know that means how many times we want to wiggle so we're going to say two times a second i'm going to say 200 pixels for the other values here we don't really care about them right now so i'm just going to hit delete and click off and now our layer is wiggling inversely if you were to see this wiggle and you were curious about what do these values mean what is 2 what is 200 if you look this up in the flyout menu you can see that the first is frequency the second is amplitude and that's what we're getting here so that snippet we had to edit some of them you don't though and some of these are really cool and things that you might not hear about otherwise i want to show you something on a path position so i'm going to enable expression and you can see we have a little circle here and from this flyout menu i'm going to choose path property create path this is relatively new so a lot of people haven't heard of it yet but if i just click that and click off we now have a square without it it's a circle but this expression is making a brand new path shape using the different parameters here you can set your points your tangents and whether or not it's closed or open all this stuff right within the expression there's a lot of cool stuff that you can do now with this new path point expression but we're not going to cover that right now unfortunately now sometimes when you're working expressions you'll either be given an existing project with a bunch of expressions in it or you found something online brought it into your project and it might be a bit hard to understand what's going on there might be a lot of lines of code there might be weird algebra or other archaic after effectsy stuff but it's very hard to know what each the components do in this example we have here we have a linear expression and linear takes these five parameters of what's your controller what you're putting what are you putting in what are you getting out fine the issue is if you were just to look at this expression you wouldn't necessarily know what the value of each of these things are so i've written this comp.duration which i know means the duration of the comp but what is that number what is the duration there's no way to see within the context of this expression so there's sort of a two-phase approach to how i like to break these things out in order to figure out what the values really are first thing i like to do to make this easier to understand is kind of separate all these fiddly little bits inside of the linear brackets into their own variables i'm just going to do this really quickly right now input is time but input minimum is zero input maximum is this comp.duration output minimum is zero again and output max is 300. now that we have those defined i'm just going to replace everything in here with what i just wrote so i'm going to say input input min input max output min output max now what linear does in this context it says as input goes from the min to the max we want to output from the min to the max so as time goes from zero to this comps duration spit out a number from zero to three hundred just in a linear way and as i scrub through my comp you'll see that's happening as time goes from zero to the end my scale is going to go from zero to three hundred great for me it's so much easier to understand complicated expressions when i separate them out like this it also makes it easier to modify the values if i want my max to be 100 scale not 300 i can just type it right there and i know it's going to work without having to figure out which spot in the brackets things have to go it's a little complicated now while this does make it easier to write i still have the issue of not knowing what the result is for some of these i don't know what duration is what if i said duration divided by two what does that number really mean what i like to do here is take it a step further like sort of make it even more modular more broken down into different components by adding expression control sliders for each of these values so in my effect controls or with my layer i'm going to go effect expression controls slider control and i'm essentially going to redo these steps just right in here i'm going to say input input min input max output min output max great now if i twirl down my effects i've got all of these i know that my input i want it to be time i want my min to be zero max to be this comp whoops duration divided by two output min 0 and output max we're going to say 100. now the last thing here is hook them up with pick whips and i know this is a little fiddly but i'm breaking it down to smaller steps if you were to write this from the beginning you'd be working with a much more a much deeper understanding sort of of what you're writing and how it's being used one last one great so at this point everything in the expression is hooked up to these sliders and i can expect that these sliders are going to control everything that i'm seeing so at this point i can see the value of all of my components before it was sort of a black box of what is time what is this comp duration rally by two but by having everything on their own slider control at every given moment of time i can see exactly what my values are i know that my input is time which at this point is almost two and a half input min is zero max is 2.5 and so on this means that i can take the output max ramp it up a little bit and i know i'm going to start always at 15 or 54 but it's more this way of thinking of everything that's dense and complicated inside of it break it out it's so much easier to see and in recent version of after effects you have this ability to drag things right from the timeline into your comp panel and see the results there as well so if you want to have like an on-screen c4d style readout of your controls you can drag this input right up here it says slider 0 because it's a slider and it makes a guide layer for it if we were to look at that expression it's going to have all the logic to hook up what this is to what we're seeing on screen but it means you get these really simple straightforward on-screen displays of your values at any given time i can just keep dragging these out and so everything's updating live and you get that feedback right in there pretty cool [Music] often when you work with expressions especially when you're downloading snippets off the internet or you're working with other people's files and trying to modify it you're going to see this dreaded orange bar this bar is telling you that there's an expression error somewhere in the project it won't tell you what the problem is but it'll tell you where to find it and if it can what line it's on mostly just telling you hey there's a fire over there you might want to go put it out we can see that there's two errors and these little buttons will go back and forth and for each one we get a line like this it's going to say error at line 1 in our case and property opacity of layer 1 and it gives you the name of it and comp and it gives you the name of it so using this we know exactly where the error is you can click this little magnifying glass icon and it's going to take you right there and highlight the property now that we know where the problem is we still don't know what's causing it that's where the second little icon comes in when you see the little yield thing you can click it and you get this pop-up these pop-ups are usually composed of three different components the first is the same as the expression bar it's just telling you why you're seeing this alert it's saying that there's an error the expression's disabled something's wrong the second one it's letting you know why there's an error or what's causing this to break the third chunk isn't always there but when it's there it's trying to tell you specifically what inside of your expression is causing the error so in this case we know where the error is and then we see reference error jiggle is not defined now this is a bit technical but reference error just means that after effects doesn't know what you're referring to you're telling it to do something called jiggle and after effects is confused it's saying we don't know what jiggle is you didn't tell us what jiggle is that's an error so knowing that it's not defined as in it's confused i can look at my expression and figure out what to go from there now if jiggle doesn't exist i do know that there's an expression that'll jiggle my layer around but it's called wiggle so i'm just gonna change from jiggle to wiggle and that's resolve the error now my jiggle is wiggling and my wiggle is jiggling a second really common error is this one we're to see here expression result must be of dimension two not one alternatively it might say dimension one not two but the idea is the same thing what this is saying is that this property that you're playing the expression to it's looking for multiple dimensions it wants an x and a y maybe a z but you're only giving it one thing so if you were to give it four it's saying well is that 4x is that for y is it for x and y what are we doing with it we don't have enough information so when you see this error message timeout dimensions that's what it's referring to it wants you to make sure that what you're feeding it matches with the expected dimensions you'll see that the most often on things like position and pointer scale where they all need x y maybe z so in this case if i look at my expression i'm saying transform rotation i want my scale values to be the same as my rotation values however rotation is just one number it's the number of degrees well that's fine for me but it doesn't know what to do with it the easiest kind of fix for this is to create a little temporary variable i'm just going to say rot for rotation and i'm going to output the same thing for both so this says that i want my x and my y both to be that rotation value and now my layer disappeared it's because my rotation is zero and so my scale is zero but as i rotate it the scale is going to match my rotation for both x and y alternatively we can set one of these to maybe not zero but a fixed number and as my rotation changes so too does the scale of one of the two values alternatively if instead of writing this myself i'm going to zero this out if i had just picked whipped rotation after effects knows that i'm taking a one dimension property and putting it on a two-dimension property and so it's going to actually add that exact same thing it's going to add in setting that one value to both x and y for me the last thing i want to show you was this little button here for show post expression graph if we just look at the graph editor right now we're going to see our two keyframes one with rotation at zero and the other at rotation at 100. however i have this loop out expression that's just going to keep my animation playing after the fact but i can't see what that looks like if i enable this button it's now going to show up this dotted line up here indicates the result of the expression independent of what you have on your keyframes this means that i can change the values of my keys and i'm going to see what this expression resolves to right there in the graph editor if i switch this over to ping pong you can see that it's going up and down and you can figure out your timing right here you can go in and add new keys and everything will update exactly as you'd expect if it makes sense with the expression this is really handy for if you're working with complicated expressions to sort of see what's going on under the hood without separating things into their own variables so i'm just going to trash all of this animation and add in something like math sine time times 2 times 100 what this is going to do is give me this nice wave here and i know that 100 means it's going to go up 100 and down 100 but i don't know what if i change this value what does that do okay it shrinks it down that's great what if i want it to be more waves i can change time times two to time times five and it's this real time feedback of seeing exactly what you're getting out from the expression that you put in that makes this tiny little button so valuable for expression development okay finally i'm gonna put it all together and talk about this fellow here who i've called handsome harry for obvious reasons um now this really puts together everything we've talked about in this little lecture including a couple of additional things like i used the linear expression a ton so i might have to go over that a little bit okay but to begin with i just want to say that saunder talks about using expressions to create complex rigs of things okay and now he doesn't do character work but this is an example of something that i've made which i think is a complex rig that uses a ton of expressions okay i just think this is a more fun thing maybe for you to play around with than like a bunch of circles moving around or something okay so we kind of created it like this and let me walk you through this i've got a ton of layers obviously and they're all shape layers and then i've got a null object here which i've made a guide layer which i've added a ton of expression controls to okay see lots of sliders a check box and angle control and stuff all right so let me just walk you through this real quick what this puppet does okay so i've built a faux parallax rig here which maybe some of you have done before but what that means is that sort of as handsome harry turns his head here it really looks like he's turning in 3d space a little bit because for example the nose moves sort of faster and farther than the other layers that are behind it quote unquote it creates a kind of faux parallax right so this is gonna work on the up and down on the x and y uh and i've also added some additional like kind of fun things in here like a brow curver you know and a brow up down so you can make them look like angry or whatever a little little check box here which you can check out which adds uh like a little blink in here uh we're giving you this after effects project so you can kind of dig through this code and see it for yourself and uh let's see i've got an additional eye slider which is really fun thing to animate i think up and down um and i put a little sort of smile frown kind of slider in here as well uh so you can move the mouth up and down as well so you can create like a ton of like expressions uh facial expressions not coding expressions on this puppet okay so like i said mostly what i used is linear so those i put on the position i split the dimensions of the position so i could move the x slider and the y slider separately okay so i have more control over it now i don't have a ton of time to go over linear but linear is pretty easy and i think sonder talks about it a bunch in the class linear i think of as being the great translator expression okay so if you want to go for example from like rotational degrees of one layer to position of another layer or something like that an example where you have values that are very different from one another and you kind of have to translate those values from one property to another linear is great for that okay so here i have my x offset slider and i've made it so that this goes from negative 200 to 200 by the way so that's the range that's the min value and the max value of that slider and i happen to know that i or i've calculated this i figured this out that when this slides all the way over to negative 200 i want my nose to be at the x position of 550 pixels okay so that's the translation here is that the min value of the slider is negative 200 the max value is 200 then the min value of the nose's x position is 550 and when this slides all the way over the max value of the nose is 13.70 okay i figured that all out mathematically and it was a little bit of a pain because i had to figure it out so that when this was at zero the nose was right back in the middle here okay so the keen observer will actually notice that 550 and 1370 are symmetrical from 960 which is the center point here i'll let you do that math yourself okay but that's about it um i just used linear that way for the x and y position of everything and um i did some other kind of fancier stuff with the ears the ears you'll see kind of need to move slightly differently and they also need to move behind the head and in front of the head like here this is behind the head and when i twirl this this way it's in front of the head so i used if else expressions and alternate copies of the ear so that basically like when it hits this position it turns itself off and the other one turns itself on seamlessly right so um it's kind of a cool rig i think you should dig through it i mean i don't think this is so complex it's not something that you'd be able to do yourself but i think this is a fun thing so check it all out and i hope you have fun playing around with handsome harry expressions are a superpower and if you want to master them check out expression session our interactive course taught by noel and zach available at school of motion don't forget to grab the free project files from this video in the description below and subscribe to this channel for more motion design content thanks for watching [Music] you
Info
Channel: School of Motion
Views: 29,317
Rating: undefined out of 5
Keywords: Motion Design, Motion Graphics, After Effects, Tutorial, Tips, Tricks, Technique, Learn, Basics, Design, MoGraph
Id: VdaGqq4I0qM
Channel Id: undefined
Length: 34min 55sec (2095 seconds)
Published: Wed Mar 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.