Roll and Rig a Cube in After Effects

In this tutorial we'll use expressions to Roll and rig a cube animation in After Effects.
Download Project File: www.schoolofmotion.com/tutori...
Enroll for Free in the 30 Days of After Effects Series: bit.ly/2tu842p
---------------------------------------------------------------------
Partial, Auto-Generated 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.

Пікірлер: 47

  • @mikesheehan5946
    @mikesheehan59463 жыл бұрын

    Wow. Loved it. Can't wait to try it

  • @leonmax3
    @leonmax33 жыл бұрын

    Amazing. Thanks

  • @sirkarmart
    @sirkarmart5 жыл бұрын

    thanks for great tutorial ;)

  • @OnurAksoy3
    @OnurAksoy3 Жыл бұрын

    A late comment after 5 years however I believe different approaches to same problem give us flexibility and contribute our perspective. I tried to solve y-axis displacement by the help of trigonometry. First, I create Null object to Control every variable. I created two sliders; one for adjust size of box and the other one for rotation. I linked Box Layer to this null object. rotation of the null object is linked to angle slider thisComp.layer("BoxControl").effect("BoxRotation")("Angle") ----------------------------------------- -> w is half size of the box or distance to centre. -> C is centre point with shifting adjustments. // Position and Center Point w = thisComp.layer("BoxControl").effect("BoxSize")("Slider")/2; C = transform.yPosition - w+100; ----------------------------------------- -> c_rad is the angle difference of the centre point to bottom corners. when the angle is 0, the angle of the centre to bottom corners is 45 degree. for every angle change, we have to add 45 degree to count resting position. I used %90 modulo operation and Absolute value operation to get rid of minus and high values. -> sin is the sinus function of centre. we need to transform degrees to radians to work. // Sin Theorem Formula c_rad = 45 + Math.abs((transform.rotation%90)); sin = Math.sin((degreesToRadians(c_rad))); ----------------------------------------- -> yDis is calculation of the distance from bottom to new position thank to sinus theorem formula ->yRot is difference between resting position. // Calculation for Center Rotation Displacement yDis = w*Math.sqrt(2)*sin; yRot = Math.abs(w-yDis); ----------------------------------------- -> Final output = Centre point - Difference // Final C-yRot feel free to check the project file: onuraksoy.co.uk/files/BoxControl_onuraksoy.co.uk.zip

  • @OnurAksoy3

    @OnurAksoy3

    Жыл бұрын

    this is for square but even we can calculate same motion for rectangular objects. clean code is here: // Position and Center Point w = thisComp.layer("BoxControl").effect("BoxSize")("Slider")/2; C = transform.yPosition - w+100; // Sin Theorem Formula c_rad = 45 + Math.abs((transform.rotation%90)); sin = Math.sin((degreesToRadians(c_rad))); // Calculation for Center Rotation Displacement yDis = w*Math.sqrt(2)*sin; yRot = Math.abs(w-yDis); // Final C-yRot

  • @bush9686
    @bush96867 жыл бұрын

    wow!)

  • @artgoyle
    @artgoyle4 жыл бұрын

    These expressions really gave me a headache... I am still curious about how to make the square so rubbery.

  • @velenkosinimmkhabela
    @velenkosinimmkhabela4 жыл бұрын

    Animations are my graphic design interest

  • @jacvanderspuy5618
    @jacvanderspuy56185 жыл бұрын

    Hi Joey. Thanks for this! Just a quick question: After you "defined" the corner points (tl, tr, etc) it seems that they stick, in other words the tl becomes the top right etc? I tried to do the animation by moving the anchor point with if statements on the rotation and it looks as if the initial orientation of the cube determines the orientation of the axes. Eg if I move the anchor point after 90 degrees rotation a change in Y value moves the anchor point horizontally??? Strange

  • @salaheddineboughanbour9729
    @salaheddineboughanbour97296 жыл бұрын

    that tutorial is the Final Boss ...

  • @alexgreene1059

    @alexgreene1059

    3 жыл бұрын

    I downloaded after effect a week ago. I’m in pain.... was sticking around for the first half tho

  • @ArisMelachroinos
    @ArisMelachroinos6 жыл бұрын

    Awesome. I thougth that the linear expression might work too here with less lines of code. I mean going to position and writing something like: linear("parent of the rotation",0,45,0,the distance from the center to a point of the square ); ?? And putting some if statements for the other rotations to cover the whole 360 range? Would it be the same result with less code?

  • @vladalecs92
    @vladalecs923 жыл бұрын

    you get the position of the corners of the comp where the square is in, is there a way to map the position of nulls inside of the comp?(so that you could have an irregular object?)

  • @arpitbansal4170
    @arpitbansal41704 жыл бұрын

    trignometric expression are way more customizable....i tried for 3-4 hrs and finally got it

  • @michalbotor
    @michalbotor5 жыл бұрын

    here's what i did: in the middle of the composition (all anchors in the middle!) i created a "Box" shape layer containing "Rectangle 1" group containing "Rectangle Path 1" (this was simply created with rectangle tool) and 4 null objects: "BoxAngle", "BoxElevation", "BoxControl" and "BoxPosition". layer's stack looked like so: "BoxPosition" "BoxControl" "BoxElevation" "BoxAngle" "Box" i used the following 'x --> y', i.e. 'x is parented to y' chain: "Box" --> "BoxAngle" --> "BoxElevation" --> "BoxControl" --> "BoxPosition" and then i used the following expressions: *) for the rotation of the "BoxAngle": // get the length of the side of the box side = thisComp.layer("Box").content("Rectangle 1").content("Rectangle Path 1").size[1]; // get the x position of the "BoxControl" xCtrl = thisComp.layer("BoxControl").transform.xPosition; // set the angle of the "Box" appropriately 45 * xCtrl / side; *) for the y position (i separated the dimensions) of the "BoxElevation": // get the length of the side of the box side = thisComp.layer("Box").content("Rectangle 1").content("Rectangle Path 1").size[1]; // get the raw angle (i.e. just as it is) of the rotation of the "BoxAngle" rawAngle = thisComp.layer("BoxAngle").transform.rotation; // manipulate the raw angle so that it's always between 0 and +-45 degrees but in radians angle = degreesToRadians(45 - Math.abs(rawAngle) % 90); // set the elevation of the "Box" appropriately 0.5 * side * (1 - Math.SQRT2 * Math.cos(angle)); *) for the y position (i separated the dimensions) of the "BoxControl": // set it to always be zero for convenience 0

  • @nathitappan
    @nathitappan2 жыл бұрын

    Any suggestions on how to tackle this if we get a 3D cube, instead of a square? I assume all the math will be the same... it's just a matter of how to figure out which axis to set the expression to?

  • @rajamomo
    @rajamomo5 жыл бұрын

    I'm new at this.. And still trying to understand. Can we use this at 3D box??

  • @DimitriBertolini
    @DimitriBertolini6 жыл бұрын

    Great tutorial! Is there a way to do the same with not regular quad? Like rectangle?

  • @schoolofmotion

    @schoolofmotion

    6 жыл бұрын

    Good question! We'd have to poke around with that one, but surely it can be done.

  • @Sapient_Army
    @Sapient_Army3 жыл бұрын

    🤯

  • @flevosap666
    @flevosap6665 жыл бұрын

    Im quite sure math.max just accepts n values...? Or not in extendScript?

  • @adegbengaojoyido550
    @adegbengaojoyido5503 жыл бұрын

    Well done sir please i have some issue on where to link Y Rotation sir with the Box

  • @machinesbreathe
    @machinesbreathe3 жыл бұрын

    What's weird is how my rig will tumble one or two times along the horizontal axis as it should only to dip down below it one square height on the third tumble. Am I calculating the lowest point improperly?

  • @asfandyar_ali
    @asfandyar_ali5 жыл бұрын

    It's fantastic, but, can we do it with Newton3 which i believe would save time. I'm not sure, Joey might suggest.

  • @schoolofmotion

    @schoolofmotion

    5 жыл бұрын

    Yep! You can do it with newton, although you'd still have to keyframe the 'wiggle' on the blocks depending on your desired density.

  • @sanketpawar8641
    @sanketpawar86413 жыл бұрын

    from where to get the rolling audio sound of the cube

  • @martincooper2175
    @martincooper21753 жыл бұрын

    Extremely late, but you were right, it can be done with trigonometry. As you mentioned, the relationship between height and rotation isn't linear, it is described by sin. If we define s as the square's side length, y position would be: -Math.abs((Math.sqrt(2)*s-s)/2*sin(Math.PI*(startPos-endPos)/s)) Just to clarify, (Math.sqrt(2)*s-s)/2, is the diagonal of the square minus it's side length divided by 2. This is the amplitude of the sin wave, as it's the distance the square will have to rise when rotated 45 degrees (it's divided by two because the anchor point is in the middle). And rotation would be: (startPos-endPos)/s*-90 , just like the video. Another thing, instead of using null objects to denote position, you can just use the valueAtTime() function of the x position at time 0 and subtract it from its value at the current time (you just put 'time' in the parenthesis). Math is cool.

  • @sarahmfarmer

    @sarahmfarmer

    2 жыл бұрын

    Hi Martin, could you explain how you set that up please? It looks elegant! when I put it in the null rotation/Y pics I get errors (sin not defined/startPos not defined...) so I must have the wrong rig up for this to work. Thanks!

  • @Zichigo
    @Zichigo6 жыл бұрын

    My brain hurt

  • @timeijs12
    @timeijs123 жыл бұрын

    46:56 you just made a box do the moonwalk

  • @suspendedhatch
    @suspendedhatch4 жыл бұрын

    Just move the anchor point to the bottom right each time the box completes a 1/4 rotation.

  • @suspendedhatch

    @suspendedhatch

    4 жыл бұрын

    The downside is that if you go to squish or scale it, it will be effected by that anchor point position. But I guarantee there's a simpler solution than the admittedly impressive one presented in this tutorial. Take it from a coder. By the time you finish your first solution, you should be coming up with a much more elegant answer. That's when it's time to start over.

  • @suspendedhatch

    @suspendedhatch

    4 жыл бұрын

    Check if X > 0 and Y > 0 to know if it's the bottom right point. Anytime you can eliminate variables, comparisons, and language objects, you reduce the overhead. Is there looping in after effects expressions?

  • @dariangarrrett721
    @dariangarrrett7216 жыл бұрын

    Could you do a tutorial on doing this sort of thing with a egg shaped object?

  • @schoolofmotion

    @schoolofmotion

    6 жыл бұрын

    Probably, but that is definitely a whole new can of worms.

  • @mitulkawa5938

    @mitulkawa5938

    5 жыл бұрын

    Or use Newton

  • @fiftypnce

    @fiftypnce

    5 жыл бұрын

    Totally. Before watching this tutorial I had to animate "olives" rolling along a "tabletop". My solution was to do it manually - no expressions, and after watching (and recreating) this process for rolling a BOX, using expressions, I can entirely imagine the headache in rolling anything egg-shaped in this way.

  • @davidcharle4869
    @davidcharle48696 жыл бұрын

    can we do with hexagon ??

  • @schoolofmotion

    @schoolofmotion

    6 жыл бұрын

    Yeah, it'd be a bit more work, but you totally could.

  • @arttonourish7852
    @arttonourish78525 жыл бұрын

    why don't we just manipulate the anchor point and position to roll the box?

  • @lamia1139

    @lamia1139

    3 жыл бұрын

    I just did that and it worked the only problem was I couldn't figure out a way to control the speed of the box since the x position value would have to be on hold till the next key frame.

  • @northwood15sa40
    @northwood15sa40 Жыл бұрын

    i am having problems with the expression, i have an unknown variable. Can someone help me?

  • @yitphady1362
    @yitphady13623 жыл бұрын

    Iam in school I need to know more .

  • @ZedTopix
    @ZedTopix5 жыл бұрын

    Oh, that's how RobTop made geometry dash...

  • @pascalarvieu6956
    @pascalarvieu69564 жыл бұрын

    I'm sorry but that's not a CUBE, that's a square…