Tutorial
No items found.

Tutorial: Rigging and Rolling a Cube in After Effects

by
Joey Korenman

Learn how to rig and animate a cube rolling.

How hard could it be to animate a cube rolling correctly in After Effects? The answer, as we found out, is very hard. This tutorial starts out by showing you how to approach animating something like a cube once you have the rig in place, because honestly we're not sure you would want to attempt animating this without a rig. You could do it using a bunch of nulls or something, but that would be painful. So if animation is your thing just grab the rig and get crackin'!

But… if you are a budding expressionista, then maybe you want to know how Joey made the rig. In that case, watch the whole video and he'll explain the entire process, including how he first tried and failed to rig this bad boy. Check out the resources tab for all the expressions you'll need to re-create this cube rig on your own.

{{lead-magnet}}

-----------------------------------------------------------------------------------------------------------------------------------

Tutorial Full Transcript Below 👇:

Joey Korenman (00:16): What's up Joey here at school of motion and welcome to day 19 of 30 days of after effects. Today's video is going to be half an animation class and half a class about rigging and expressions. What we're going to try to do is tackle the problem, which was actually much trickier than I thought it would be. Uh, how do you make a cube or a square that can roll accurately? You know, if you think about it, there's a lot of logistical problems involved in doing something like that. So, first I'm going to show you how to animate the cube. Once you have it rigged then for the geeks out there. And I know there are some geeks out there I'm going to walk you step by step through how I built the rig. I'm going to show you the expressions and explain how they work. Then of course, I'm going to give you everything you need to build the rig for free.

Joey Korenman (00:59): Or if you just want to practice your animation skills, you can grab the completed rig too. All you need to do is sign up for a free student account. So you can grab the project files from this lesson, as well as stuff from any other lesson on the site. Now I want to go into after effects and show you some cool stuff. So let's go do that. So for the first part of this video, we're just going to talk about how to animate a cube kind of tumbling. Once you have the rig set up. And then after we do that, I will walk through how I actually came up with and made this rig and I'll copy and paste the expression code onto the site. So if you guys don't want to watch that part, feel free to just copy and paste the code and it should work for you.

Joey Korenman (01:40): So there's a lot of things going on here that make this animation work and the rig is part of it. There's also just a lot of animation principles and really precise, key framing and animation curve manipulation. So I wanted to talk about that first. So what I have here is a copy of the scene with no animation on it. And I do have my rig set up. So the way this rig works is there's a bunch of NOLs in the nose, all do different things. And we'll talk about that in the second part of this video, but the one that you control is this Knoll here, box control. Oh one. And I labeled this oh one because in the demo I had two boxes. So I had two sets of controls. So this Knoll, literally, if you just move it left to right, like this, the box roles correctly, based on where that knowledge is.

Joey Korenman (02:30): So if you just wanted the box to just kind of simply roll across the screen, all you need to do is move the nuts real easy. I wanted it to feel like the box got kicked or something and sort of landed like this. So the good thing about having a rig that takes a lot of the manual labor out is I literally only have to key frame one thing, the exposition, the rotation, uh, and really the trick is that the box has to move up and down a little bit as it rotates to always keep it touching the ground. If you look at this B this box adjust, why not right here, um, that actually moves up and down. Let me move this box back and forth. If you keep an eye on it, it's this snow right here. It actually moves up and down as the box rolls.

Joey Korenman (03:19): That's kind of, what's doing the trick there. So why don't we start out by just animating the exposition of this box? So we'll have it start off screen. I'll put a key frame here and then let's go forward. I don't know, a couple of seconds and we'll have it roll out to the middle of the screen. And I want to make sure that it lands totally flat on the ground. And it's, it's going to be pretty tricky to do that because all I'm animating is the exposition and I can kind of eyeball it and say all that looks right, but how do I actually check and make sure that it's flat on the ground? Well, let me unlock this and all this and all here. The be rotate for box rotate. If I open up the rotation properties of that Knoll, the zero station has an expression on it.

Joey Korenman (04:01): And that expression is what's actually setting the rotation. And then I have my, my box parented to that Knoll. So the Knoll is rotating. The box is parented to the Nolan. That's why the box rotates. So what I can do is I can just reveal the rotation property and slowly adjust my exposition until I get this to, to be a flat zero. And so I can just click on the exposition and use my arrow keys. And you can see if I hit up and down, it actually jumps over and misses the perfectly zeroed out rotation. But if you hold command and use the arrow keys, it adjusts the numbers at it, sort of at a smaller scale. So now I can really precisely dial that in. And now I know that the box is flat. So if we just do a quick grand preview of that, you've already got your box kind of tumbling with two key frames.

Joey Korenman (04:55): There's, that's why I love rigs and expressions because you know, it takes a lot of time to set them up. But once you do, you can get all kinds of really complex movement with almost no effort. Um, so think about, let's think about the speed of this, right? If, uh, you know, if someone kicked this little box guy and he was going to land over here, what would happen? And this is where having some animation training and, you know, reading, reading a few books about animation and just kind of learning as much as you can. It can help you understand how you should animate things, right? If you kick something and it's tumbling through the air, what basically happens is every time it makes contact with the ground, it's going to lose some of its energy. And because this box is right now, it's constantly in contact with the ground.

Joey Korenman (05:43): It's going to be losing momentum all the way through the animation. So what it should be doing is moving quickly at the beginning and then slowly, slowly, slowly coming to a stop. So let's select those key frames, hit F nine, easy ease. Then let's go into the animation curve editor and let's bend the Bezier like this. So what I'm doing is I'm saying the first key frame, there is no easing out. It just pops right out really quickly. And then that last key frame right here, I want it to ease into very slowly. Cool. Now it looks like it got kicked and it's sort of slowing down there. Okay. Now that's not, you know, there's, there's a lot of stuff wrong with this right now. Uh, obviously when it, when it, when the box tips over here, it shouldn't slowly settled into the ground like that because the box has to follow the rules of gravity.

Joey Korenman (06:32): It's gonna, it's going to tip and land and, and, you know, the, the way I had it do and the way I had it work in this demo, and don't worry about the bouncing, I'll show you how to do that too. But it, oh, it sort of lands here and all, you know, it doesn't quite have enough energy. So then it bounces back the other way. So let's make it do that. So what I actually want it to do is when it gets here, I want the box to be a little bit further. I want it to, so I'm just adjusting the exposition. So it ends up not quite at a 45 degree angle. So the weight is still on the left side of the box. So it's going to have to fall back down. So now let's look at this. Okay. So let's get in there.

Joey Korenman (07:14): It's better. Okay. But it feels like the box is defying gravity. Like it's just slowly lifting up it's it's foot at the end there. And so what I really want is I want that last move, right? I just want this move to feel like that's where all of that energy really starts to slow down. So what I want is I w at this point in the animation, I still want that box moving quickly. So what I'm going to do is I'm going to hold command. I'm going to put another key frame here, and I'm going to scoot that key frame backwards. And what this is doing is it's letting me create a type of curve where there's, there's a really fast move at the beginning. And then after a certain point, it flattens out very quickly. And it's easier to do this with three key frames than it is with two.

Joey Korenman (08:06): And so now if I play this, you can see that it's sort of all that momentum dies out kind of all at once. And I'm just going to scoot this over a little bit and try and find the sweet spot for it. Okay. And, you know, I might want to move this a little bit, maybe so that the box is lifted up a little bit before it really starts to lose its energy. Okay. So that's getting there, but what's happening is when this box does this final sort of fall right there, it's easing into that key frame, which I don't want. So I need to manipulate these curves. I need to bend them and really make them, and you can see, we're starting to get some weird little points and things like that. And that's going to, okay. Now, normally when you guys have seen me in the animation curve editor, I try to make the curves really smooth and avoid stuff like this.

Joey Korenman (09:02): That is a rule that, that just in general can make your animations feel smoother. But when things are obeying gravity and hitting the ground, that's a different story because when things hit the ground, they stop instantly. And the energy transfers instantly to different directions. So when you have stuff like this, you are going to have a little points in your animation curse. Okay. Now it's feeling better, but it's happening too quickly. So I just need to just flatten it out a little bit. That's better. Okay. All right. And really, you can see how you, you know, you, I'm just doing little adjustments to these Bezier curves and it really can make or break your animation. And this just takes practice, just watching your animation and figuring out what the problems are with it. Okay. So I like how this part feels, and then it leans up and I want it to hang there for a second.

Joey Korenman (09:56): And then I want it to start coming back the other way. So I'm actually gonna move this key frame a little closer, and now it's going to tip back this way and let's, let's try, let's try 10 frames. So I hit shift page down, jumps me for 10 frames. And sometimes I just like to work right in the curve editor. Cause it's, it's just a nice visual way of working hold command, click on this dash line and it'll add another key frame. And then I can pull that key frame down. And I want that cube to overshoot and come back a little too far. And the way this is going to work is it's going to ease out of that first key frame. And it's actually going to ease into this key frame. But what I need to do is go to the frame where it hits the ground and make sure that my curve is not easing at that point.


Joey Korenman (10:44): And this may be, this is a little confusing. It's actually, it's kind of hard to explain, but you want to make sure that as the cube falls, it's accelerating and it has to accelerate and acceleration in an animation curve means it's getting steeper and steeper and steeper and steeper. Once it hits the ground and it starts to come back up. Now it's fighting gravity and that's when it can start easing. So you can, you can, you know, you can help it. If you need to, you could put a key frame right here and that, and then you have control over this and you can make it even steeper if you want to. Um, I'm going to try without doing that and let's see what we get. So it leans and comes back. Okay, cool. Now that lean, I like what it's doing. I kind of want it to happen a little bit faster. So I'm just going to move all these key frames closer.

Joey Korenman (11:36): All right. Maybe not that fast. You can really just depends how anal retentive you are. I guess I could really just do this all day long. So, all right. So the box hits and liens, and I'm just going to pull this handle out a little bit more. There we go. And you can see it almost makes it, and there's even, this is unintentional. I didn't do this on purpose, but it even leans a little bit farther. Like it's trying to reach and it doesn't quite, um, and that's kind of interesting. So I'm gonna, I'm going to leave that, but I just want to make it not so strong. So here we go. So falls and then it comes back. Okay. So now it comes back this way and then I'm going to have it overshoot one more time. So each time there's a move, it's going to take less and less time because you know, the, the distance it has to fall is getting less and less.

Joey Korenman (12:32): So let's just go forward a few frames and let's move this key frame back to here. So it's just barely off the ground. All right, let's pull these handles out. Let's double check that when the, when the box is touching the ground, see, so now the box is touching the ground on this frame, but I can see that this curve is starting to slow down already and I need to make sure it doesn't do that. So I'm going to pull this busy a handle out. So it's steeper on the point of the animation curve, where the box is, is touching the ground. And then it's going to one more, one more position here. What's actually going to settle onto the ground. And for this, I need to make sure that it's actually sitting on the ground. So I'm going to do that little trick where I select this value. I hold command. And I'm just going to nudge the values until I get to 360 degrees, which means it's flat on the ground. Let's play our animations heat. We got so far.

Joey Korenman (13:31): Cool. So there's, you know, there's a few little timing issues. I feel like it's too slow at the end. So that's an easy fix. I'm just going to grab these last few key frames, hold option and scale those last few back a few frames. Cool. All right. Now this animation, I, you know, I, the little hang right there, maybe it's a little too long, but overall, this feels pretty good. It gives you a sense that there's weight in that the box, you know, has momentum and all of those things. And, and what's great is we've literally only had to key frame one property to get all of this cool complex motion. So now let's talk about having the balance box, uh, sorry. The box bounce a little bit, um, by doing the Y position. So I know that in the end, I'm going to want it to land here.

Joey Korenman (14:20): All right. So that's the final Y position. Um, so why don't we start by saying, okay, let's have the box bounce. Maybe this is where it lands on the first bounce. I'm going to put a key frame there on Y position. Then I'm going to go back to the first frame and I'm going to raise up the box. Okay. So how high do we want it to be you when it comes in? Maybe there, maybe that's good. Okay. So now let's easy ease these key frames, and let's go into the graph editor and let's talk a little bit, and this is, this is a topic that actually, um, this is one of the first things that, that I would teach, uh, students at Ringling, uh, when we're getting into, after effects is how to do a bouncing animation. Cause there's a, there's some rules that bounces follow.

Joey Korenman (15:04): So one of those rules is, as something is falling, right? If it's starting up here and someone drops it, right, let's pretend someone dropped it. Or, or that this is the apex of a bounce that we can't see back here. It's going to ease out of that bounce. It's not going to ease into the floor though. Right? Gravity makes things accelerate until they hit something. So that means that handle needs to be shaped like this. So that first fall needs to look like that. Now the ball's going to bounce a little bit and the rules of a balance are essentially this, the height of each balance is going to decay following a decay curve. Um, and you can Google bounce, decay curve. And I guarantee you'll find like a little drawing of what it's supposed to look like. Um, and then when you're key framing it and using the animation curve editor, there are some rules that you can follow to help it look more natural.

Joey Korenman (15:58): So one of those rules is each bounce is going to take less and less time. So this bounce we're starting at frame zero hits the ground at frame 11. So what that means is that this bounce, if this was a full bounce, would have taken 22 frames. So that means the next bounce has to take less than 22 frames. So why don't we say 10 frames? So I'm going to jump forward. 10 frames, put a key frame here, and now I'm just going to bend these Bezier handles like this. Okay? And the rule you want to follow is when the box, when the, when the box or whatever is bouncing, comes into the ground, and you can see the angle, this Bezzy is making, it's going to bounce off the ground at the same angle. So you don't want to do this and you don't want to do this.

Joey Korenman (16:47): You want it to try. You want to basically a good trick is you put your play head right on that key frame, and then you try and make this symmetrical, okay. And then you want to do the same thing here. You want to make this angle more or less match this angle here. So now let's do a little Ram preview. So it balances, and that's actually kind of cool the bounce. So the bounce is happening kind of slowly, but it worked out just luckily that it's almost like the box bounces and catches itself, like a little ballerina. It's fun. I love when I do things accidentally that are actually pretty, pretty cool. Um, and I just want to see what happens if I take these key frames now scale them just a little bit. Yes. And now here we go. That's great. So now what's happening is that it's landing on the ground slightly before and then catching itself.

Joey Korenman (17:38): So I'm just moved these key frames a little bit. Um, and if you wanted to, you could even add one more bounce, which might be kind of cool. So this bounce from here is frame 10 to hear stream 19. So this bounce was nine frames. So the next balance needs to take less than nine frames. Uh, and you know, there, you could figure out exactly the right number of frames. If you wanted a perfectly physically accurate bounce, we're just sorta eyeballing it here. So why don't we make it? I don't know, five frames. So go 1, 2, 3, 4, 5, put a key frame there and we'll just have it do a little bounce. Now you saw what just happened. I pulled this Bezier handle it, screwed this thing up. If that happens, it means the Bezier handles on this key frame are locked together. So if you hold option, now you can break those handles and make sure that the angles are symmetrical.

Joey Korenman (18:28): There we go. And let's see now. Yeah, like that. That's fantastic. It's, it's funny. Like this looks totally different than the demo that I showed you guys at the beginning of this video. Um, but it's kinda nice. It's kind of quirky. And again, I want to just call out that all we've key framed is X position and Y position on this Knoll and all of that rotation and all that stuff is happening for free, which is great. And now, you know, let's turn on some motion blur and, and we're going to get a nice little cute animation. For some reason, I've been into really cute little shapes and eyeballs and stuff like this lately. So that's that, that shows you how once you have this rig, you can really, really easily animate this stuff. Um, and you know, if you look at the demo that I did, I mean, there's, there's a little bit of more sort of fancy compositing going on.

Joey Korenman (19:22): Um, this giant box is animated the exact same way. The only extra thing was I used an effect called CC bend it, and, uh, that effect just bends layers. And so I wanted that one because it's so big to feel a little bit Gigli. And so I just use that to bend it a little bit. Um, but that's a pretty simple trick. So now let's get into, and I'm gonna use this opportunity to say, if you do not care for expressions, um, you know, hopefully you'll grow out of that, but, uh, that we're going to get pretty deep in the woods. Now, um, now this, this rig, it's not that complicated. There's a lot of, I mean, the code for it is a little bit long, but it's not as math heavy as I thought it was going to be originally, when I set out to do this, this is what I did.

Joey Korenman (20:10): I took a box and I put a little guide at the bottom of it, and I just rotated it just to see what happens. And obviously what you notice is that the box, as it rotates, it breaks the ground plane. And so I knew I needed to lift that box up somehow based on the rotation. So when it's rotated, you know, zero degrees or 90 degrees, it needs to not move, but as it rotates, it needs to go up and down. And so I, at first I thought maybe I could ride an easy expression where as the rotation goes up to 45, cause 45 degrees, that's where the box is going to have to lift up the most. I thought maybe I could just write an expression where, you know, the, the, the Y position of the box is based on the rotation of the box.

Joey Korenman (21:01): The problem is that there's not a really simple relationship between how high the box needs to be and how much it's rotated. If it's rotated 10 degrees, it still needs to lift up. But, but as it's rotated 20 degrees, it doesn't need to lift up nearly as much. So there's not a one-to-one linear relationship between rotation and height. The next thing I tried was very painful and I tried figuring out some trigonometry. And I dunno that probably says a lot more about me than about the way you should go about doing this. But I was trying to use trigonometry to figure out, can you figure out based on the rotation, how much taller this cube is getting, and, and, you know, I got close with it, but maybe I'm not good enough at trigonometry. And I'm sure that there is a way to do it with co-signs and signs and tangents and all that.

Joey Korenman (21:56): But then I remembered, and this is where just knowing what's possible with expressions can be amazing. I remember that there are some expressions in after effects that will let you, for example, figure out where on screen. This point of this layer is no matter where this, this cube is rotated. It can tell me where this corner is, right? So as I rotate it, I can have a value that tells me exactly where that corner is. And I could, what I could do then is put an expression on the cube to figure out the top left top, right, bottom, right bottom left, to figure out where those corners are on screen at all times, figure out which of those corners is the lowest, and then figure out the difference between where that corner is and where the center of the boxes. Now, I don't know if that made any sense, but we're going to start making this expression and hopefully it will make sense as we go.

Joey Korenman (22:52): So let's start. I hit F1. I brought up the help for after effects, which is funny because I actually did that when I was trying to figure this out. All right. So let's make a Knoll, you know, object. We are going to call this the B rotate null, and I'm just going to parent the box to it. Now, the reason I'm doing that is because whenever I make a rig, I try to think ahead and, and say, you know what? This box is not always going to be the box that I'm going to want. Sometimes I'm going to want a bigger box or a smaller box or a red box. So I'd rather rotate a no, and then have the box just parented to it. Okay. So now if I rotate the Knoll, there you go. The next, no I'm going to make, so let me just duplicate this and I'm going to call this B Y adjust.

Joey Korenman (23:38): So this now what I need this to do, and I'm going to parent the rotate and all to it. This I'm going to need to separate the dimensions and have the Y position adjust based on the rotation of this Knoll here. So if I rotate this, I want this null to automatically rise up like this, so that the bottom of the box, where ever that happens to be lines up right on that line. Okay. That makes sense. There we go. So let's rotate that back to zero, and let's set that back to five 40 and now we're going to start talking about expressions. So here's what we need to do. First thing we need to do is figure out how big this layer is. This little box layer, because what I need to do is tell after effects to sort of track the top left corner, right.

Joey Korenman (24:30): Corner bottom, right. Bottom left. And I can't do that if I don't know how big the boxes, while I was very smart, when I made this box and I made it 200 pixels by 200 pixels, so very easy numbers. And so what I can do is I'm going to put an expression on the Y position. So let's hold option, click the stopwatch, and let's get rolling. All right. And we're going to, we're going to define some variables first. So the first thing we need to know is what is the length of one side of the box, right? What are the dimensions of the box? So I made a variable called box D for dimensions, and I'm going to say that equals 200. Okay. So if I know that one side is 200 pixels, what are the coordinates of each of these corners? So the way after effects works is the anchor point of my layer is the zeros zero point of my layer.

Joey Korenman (25:27): And you can see the anchor points right in the middle. So as we move to the left, our X value is going to turn negative. And as we go, right, it's going to turn positive for Y values. If we go up, it's going to turn negative. And if we go down, it's going to turn positive. So what that means is this corner here is negative 100 negative 100, and then this corner is positive 100 negative 100. So that's how you can figure out where the corners are. Um, so because the anchor points right in the middle, and we want to go back half the length of the box, I'm then going to say, D equals box D divided by two. So that D that is now a variable that tells me how far to move, to find these corners. So now I'm going to define the actual coordinates of the corners. All right. So I'm just going to say top left T L equals. And what I want to do is use an expression called two world, and I'll explain why in a minute, but the first thing I need to do is say that I'm looking at the layer B rotate, because B rotate that null, that is what's going to actually rotate, not, not, not the box one layer, but the rotation null is going to rotate. And so, as it rotates, let me just hit, enter for a minute as this rotates, right?

Joey Korenman (26:56): The corner of that null, which just happens to correspond perfectly to the corner of my cube, that is going to move through space. So I'm looking at the layer B rotate, and I'm going to use an expression called two world. And what two world does is it translates a coordinate on a layer. For example, this, this bottom right corner is going to be 100, 100 on that layer. And as it rotates, it's going to move through space. Now, the coordinates of that point doesn't change on the layer itself, but it does change as to where it exists in after effects is world to world, converts that point into a world, coordinate for me. So it's the layer period to world, and then you open print the seas, and then you tell it what coordinate to convert. So the first coordinate I want it to convert is the top left corner.

Joey Korenman (27:57): So the top left corner remember is negative 100 negative 100. Now I don't want to just type in those coordinates. I want it to get the coordinates from this variable here. So if you remember, D is our box dimension divided by two, so D actually equals 100 right now. So if I type in and you have to do this in brackets, because we're going to put in two numbers, if you said negative D comma, negative D close the brackets, close the parentheses semi-colon, there you go. That's the F that's how you, you have to structure this. So again, it's the layer two world. And then the coordinate on that layer. You want to convert into world coordinates. Now let's do the top, right? And I'm just going to copy and paste this one. Don't have to type it in every time. So we paste it. We change the variable name to top, right? So now the top right corner coordinate is 100 negative 100. So that first number is positive. Okay. And then we're going to do the bottom left coordinate. So that's going to be negative 100, 100. So now it's negative, positive.

Joey Korenman (29:05): And then finally bottom right. Is going to be positive, positive, and what makes it even great? What makes it even more confusing and awesome is that when you get into cinema 4d, uh, it doesn't work that way. Um, it actually, the, the X and the Y values, um, that they're reversed. So I believe that might see now I just said it now I'm self-doubting so someone correct me if I just made that up. So now what we've got is we've got these four variables TLTR BLBR and those coordinates, uh, are literally world coordinates now, which is fantastic. So the next step is to figure out which of those coordinates is the lowest one. Okay. So let me just show you here. So if we have, for example, let's say we rotate this like this. Okay. The bottom right corner is the lowest one. If we wrote, if we keep rotating it though, now the top right corner is the lowest one.

Joey Korenman (30:10): So we need to know which coordinate is the lowest one. And so what we're going to do is we're going to make some new variables here and what I basically want to do. So each of these variables, top left top, right, bottom left, bottom, right? These contain two numbers. They contain what's called an array, and it's an exposition and a Y position. And I don't really care what the exposition is. I just care what the Y position is. So let's pull out just the Y position here. So what we can do is, uh, we can do it two ways. Um, I could just keep adding to this expression and tweak it a little bit. Um, but to make it less confusing, I'll just do it as a separate line. So why don't we say the top left Y position equals that top left variable and then in brackets a one.

Joey Korenman (31:03): Now why a one? Well, when you have a, when you have a, an array with two numbers, right? This variable T L right now, if you were to look at actually what the value of it is, it would look like this. It would be negative 50 comma, negative 50, right. X then Y and I don't care about X. I just want Y so this is the, this value here has a number. And this value here has a number, sort of like an index, and it starts at zero. So if I want the X value, I would make the zero. And if I want the Y value, I would make it one. So that's what I'm doing. There we go. And now I'll just copy and paste this three more times, and I'll just change the name. So this is going to be T R Y position B L Y, position and B R Y position.

Joey Korenman (31:52): And then I'll just change these variables so that we're getting the right ones. Okay. So now I have these four variables here, which only contain one number, the Y position of the corner. So now let's figure out which one of these is the lowest on screen. So here's what you could do. There's actually, um, there's a bunch of ways to do it. You could write out a bunch of if then statements that sort of check. If this one is lower than this one, then let's use that and then check the next one. If this one is lower than this one, there's a little shortcut. There's a command, uh, called max. And there's another one called minimum. And it basically lets you compare two numbers and it will just tell you which one is to higher or lower based on what you want to know. So what I'm going to say is the lowest Y equals.

Joey Korenman (32:41): So I'm making a new variable and to find that lowest, Y I'm going to use a command called math dot max. And when you use this math command, you have to capitalize math, just one of these weird, confusing things. Most things are lowercase that one's upper case. And then dot max, the math command, which actually, if you click on this little arrow here, um, it's in the JavaScript math section here, and you can see there's a whole bunch of different things you can use. And so we are using this one math dot max, and you give it two values and it tells you which one is the highest or the maximum. Now it may be counterintuitive. We want to know which one is the lowest on screen. But remember in after effects, the lower you go on screen, the higher, the value of Y gets.

Joey Korenman (33:29): And when you go up on screen, why gets negative? So the lower the value is, so that's why we're using max. And I'm just going to check between the first two variables T L Y position and T R Y position. Okay, so now the lowest Y variable is going to contain whichever of these numbers is the highest meaning the lowest onscreen. So now we need to check the other variables. So I'm just going to do the same thing again, lowest Y equals. And this is a cool trick you can do with an expression is I now want to take whatever the variable currently is lowest Y so I can actually use the variable to examine itself. It's like being John Malcovich or something. And now I'm going to add the next variable, the bottom left Y position, and then I'll do it one more time.

Joey Korenman (34:27): So lowest Y equals math dot max, look at the lowest Y and then examine the bottom, right? Y position. And as I'm doing this, I realized they didn't name these variables correctly. This should be bottom, right? Y position. There we go. Cool. So I hope you guys can understand what's going on here. I'm just literally kind of iterating through each of these variables to compare all four of them and figure out in the end, which one has the, which one is the lowest on screen. And I probably should have named this differently. I'm looking for the lowest one on screen, but actually the highest number. So lowest Y actually contains the highest value, but it's the lowest position on screen. So now after all this work, we have a variable that tells me where on screen. The lowest point of that cube is no matter how I rotate it.

Joey Korenman (35:26): So the next thing I can do is, um, I can take that value, right. So, and let's kind of, let's talk through this a little bit. All right. Um, and actually w what just happened because, oops, let's see what happens if I rotate this now. Okay. You can see that some stuff is starting to happen. Now. I haven't really set this up correctly yet, but this is what I want you to think about the B rotate. No, um, is right in the middle of our layer. Okay. And, and what I really want to find out is where is the, you know, what is the difference between the bottom of our layer when it's on the floor and the bottom of it, once it's rotated. So what I'm going to do is I'm going to make one more now, and I'm going to call this box control box CTRL.

Joey Korenman (36:22):

And I'm going to just temporarily parent this to my box and position it at 100 comma, 200. There he goes. So now it's at the very bottom of the box. Then I'm an unparented. And now I'm going to parent the box, sorry. I'm going to parent the B rotate null. Nope. I'm see. I'm telling you guys lies. Box is parenting. I knew I was going to stumble through this. I knew it, the box his parents did to the rotate and all the rotate. And I was parented to the why adjuster and the why adjuster. I now want to parent to the box control. So now we've got this nice parenting chain. All right. And that's going to screw some stuff up, but don't worry. And I want the box control to end up right in the middle, right on this floor right here. Okay. And let's go to the Y adjust and just turn this off for a minute.

Joey Korenman (37:13): Okay. And let's think about this. So if my box control, and now, now everything's all messed up, but don't worry about it yet. If what I want to find out is my box control Knoll is here. Okay. I know where it is. And I'm also going to know where the lowest point of my boxes, right? So if the box is rotated, let me turn off the, let me turn off this expression for a minute. So I can demonstrate this, right. If my box is rotated like this, I want to measure the distance between my box control, Knoll and whatever, the lowest point of that boxes does that make sense? Because then I can adjust it up by that amount. So that's the key to this whole setup here. So what I need to do is now go into this expression and I need to add a little part.

Joey Korenman (38:12): I need to add something up at the top here. I need to find out the why position of my box control now. So I'm going to say control Y position equals, and I'm going to pick whip this layer, and I'm going to use the two world command just like I did here. Um, so that way, if I make this into a 3d, or if I move a camera around it, it should still work. So two world print, the, and the, the coordinate I want to put in there is zero comma, zero, because I want to find out where the anchor point of that knowledge is. Okay. So there you go. So now I have two values. I have the control points, Y value, which is here. And then I have the lowest point of the cubes, Y value, which is here. And what I want to do is subtract one from the other. Um, and I honestly, I can't remember which one to subtract, so let's just try it this way. Let's try subtracting control Y position minus lowest. Y let's see what that does. [inaudible]

Joey Korenman (39:25): All right. So we are, I know what's going on here. See this little warning. Let me try to troubleshoot this with you guys. It's telling me error at line zero. So I know it's, um, I know that it's something going on. It actually does. I don't think it is lion's hero, but let's take a look at this, uh, the Y position of layer two, blah, blah, blah, must be of dimension one, not two what's going on here is, uh, I am I set this variable incorrectly to control Y position equals the box control layer two world. And the problem is that this two world is actually going to give me an X and a Y. And all I want is the Y. So remember to get the Y you just add bracket one, and there we go. So now as I rotate this, it's going, there you go.

Joey Korenman (40:14): It's working, dear God. And this is, this is actually the, the, the, um, this is sort of how I acted once I finally figured this out. It just, I couldn't believe that it worked. So let me try and just walk through it one more time, because I know that this is probably goggled gobbledygook in your head right now. I have a Knoll, the box control Nolan. Let me, let me, um, let me actually move this. Let's see here. Where's my box control. No, there we go. I just adjusted the Y position of the Bya adjustable so that I could, um, I could put that box control mode right on the bottom. So if I rotate this cube now, right, it's always stays on the floor. And remember, the reason that's happening is because I'm tracking the four corners of it. And wherever those four corners are and figuring out what, which corner is the lowest.

Joey Korenman (41:05): So right now it's this corner, but here it's this corner and whichever corner is the lowest and figuring out how far below my control Nall, it's going. And then I'm subtracting that amount to bring it back up to level with the floor. Boy, I really hope you guys could understand this because, um, you know, I know that if you've never used expressions is probably, isn't making a lot of sense, and you may have to watch this video a bunch of times to really comprehend this. And what I, what I'd love you guys to do is actually go through the painful process of typing in the expressions. For some reason, typing them in helps solidify the concepts in your mind. Um, but you know, now it's working. And so now I've got this rotation, null that is gonna, you know, get, give me this automatically super simple.

Joey Korenman (41:53): Cool. So now the next step is how do I make sure that as I move my control Knoll around it rotates the correct amount, because you know what you could just try doing is say, let's put a position, key frame here and another one here and move this. And then we'll just put key frames on rotation and we'll just have it rotate 90 degrees. And if you're lucky it'll work, but you can see, even, even in this example, it looks like it's kind of gliding across the ground. It's not stuck to the ground, and it's going to be very hard to manually get that to work, right. Especially if you're trying to do kind of more complex movements like this and have it land and then stop for a minute and fall back. I mean, that's going to be really tricky. So, uh, I wanted the rotation to happen automatically based on where this thing is.

Joey Korenman (42:45): So what I figured was that each side of this cube is 200 pixels. So if it's going to rotate 90 degrees, it's going to move 200 pixels. So all I needed to do was make an expression that would rotate this 90 degrees for every 200 pixels. I moved this now, how do I know that I've moved it 200 pixels will first, I need a starting point to measure to measure from. So I made another Knoll, one more Knoll here, and I called this box start position. And th and I'm going to put this Knoll level with the ground here. So I'm going to look at the Y position of box control and it's six 40. So let me put this at six 40 and you know, so, so this box control all its or the starting position. All it's going to do is it's going to give me a reference point where I can measure the distance between this in my control Knoll, and that will control the rotation of the box.

Joey Korenman (43:46): And this is a pretty simple expression. So I'm gonna put an expression on rotation for the B rotate now. And what I want to do is compare two points. So the start position equals this, no dots. And again, I'm gonna use this to world command, um, just in case. Cause if this will work, but as soon as you make things 3d and you start moving a camera around, if you don't have that two world your values, aren't gonna be correct. So I'm gonna say two world parentheses brackets, 0 0, 0, sorry, just zero, zero. I'm just looking at the anchor point of this and then I'm going to, and then I'm going to, I'm just going to add the bracket zero to this because now all I'm concerned with is the exposition, right? The distance between this and this, but only on X. And I didn't include why, because I knew if this box was bouncing up and down, I didn't want that to throw off the rotation.

Joey Korenman (44:49): I only want the rotation to be based on horizontal movement. So that's why that bracket zeros there. So then the same thing for the end position equals. So end position equals, um, we're looking at the control. No right here. So we're looking at this dot two world parentheses bracket, zero, zero close bracket, closed parentheses, and then add that bracket zero to the end. And now I've got start position in the end position. One thing that used to trip me up all the time is when you use the two world, um, command or expression, you don't use it with the position property of the layer. You don't do this to world. That won't work. What you have to make sure you do is you actually need to pick whip and select the layer itself and then use two world. So if, if you're having trouble, make sure you're doing that. And then all I need to do is figure out how far this thing has moved. So I have the start position. I have the end position. So I'll just say start position minus end position. So that's now the difference, right? The distance that it's been moved, I'm going to put that in parentheses and then I'm going to multiply it by 90.

Joey Korenman (46:13): Okay. Um, let's see here. I'm missing a step. I know what it is. Okay. Let's think about this for a minute. If this thing moves, if our control Knoll moves 200 pixels, that means that it should rotate 90 degrees. So what I actually want to find out is how many times this thing has moved 200 pixels away and then multiply that number by 90. So I actually need to get the difference between the start and the end divide by the length of one side of the box, which we know is 200 and then multiply the result of that by 90. There we go. So now if I move this box control, no, that's kind of interesting. All right. So it's rotating. It's just rotating the wrong way. So let me multiply it by negative 90 instead, and now let's move it. And there you go.

Joey Korenman (47:14): And now you've got this great little control scheme, um, that ladies and gentlemen, that's the rig. That's how it works. Uh, I added a couple of other little helpers. Um, you know, some of, you know, a good rule of thumb when you're making an expression. Any time you have a number like this, this 200 that's hard-coded into this expression. So if, for example, I decided instead of box one, I wanted to use box two, which is a much bigger box. Well, now I have to go in and change this expression. And I also have to go and change this expression because it's hard coded in here too. And that doesn't take that much time, but it's, you know, it certainly would be a pain if you had a whole bunch of boxes. So what I did was on this box control Knoll, I added a nice little expression, slider control, and I just called this box side length.

Joey Korenman (48:12): And that way I can tie this number to any expressions that need to use that number. So box one, let me replace box two with box one again, and I'll show you how to, how to adjust this. So we know that box two has a length of 200 for each side. So now what I'll do is I'll make sure that I can see this slider. So I just hit E to bring up the effects on my note. And then I open this so I can see it. Now let's double tap you to bring up our expressions. And instead of hard coding, 200 in there, I'm going to pick whip to that slider. Now, whatever that slider is set to is actually the number that will get used. And in this expression, that's all I have to change. Now on the rotation expression, I just need to do the same thing instead of 200.

Joey Korenman (48:58): I can just pick whip to this and there you go. And now the beauty is if I swap out a different box, right, right now it's not going to work, right. But if I change the box side length to whatever the correct sizes, which box two is 800 by 800. So if we switch this to 800 now, and now I move this, this box will now rotate correctly. So now you've got a very versatile rig, which is very important. And, you know, you could probably, I don't know if you guys are like me, you can probably think of 10 other things that you could add controls for. Um, but this, this in essence is really all you need to do to start animating these boxes. So this was an interesting one. Uh, we kind of hit some animation principles in the beginning, and then we really went deep with the expressions and making a box rig.

Joey Korenman (49:51): And I hope that there was kind of something for everyone in this tutorial. I hope, you know, if you're a beginner and you're just getting the hang of animation, I hope that the first part was really helpful. And if you're more advanced and you're really digging rigging and expressions and want to learn more about that, um, then hopefully the second part of the video was helpful. So thank you so much. And I will see you guys next time. Thank you so much for watching that. I hope you learned not only something about animation, but also something about problem solving and after effects and how to approach tackling an expression rig. I know a lot of you maybe haven't done that yet, but just what's possible can sometimes open up a lot of opportunities in after effects. If you have any questions or thoughts about this lesson, let us know.

Joey Korenman (50:35): And we'd love to hear from you if you use this technique on a project. So give us a shout on Twitter at school emotion and show us your work. And if you learn something valuable from this video, please share it around. It really helps us spread the word about school motion. And we definitely appreciate it. Don't forget to sign up for a free student account so you can access the project files from the lesson that you've just watched, plus a whole bunch of other neat stuff. Thanks again. And I'll see you on the next one.

Success! Check your email (including spam folder) for your download link. If you haven't yet confirmed your email with us, you'll need to do that one time.
Oops! Something went wrong while submitting the form.
Featured
No items found.
No items found.