Squash and Stretch in After Effects

Squash and Stretch in After Effects


Hey there, Joey here for School of Motion,
and today we are going to talk about one of the principles of animation, squash and stretch. If you’re not sure what animation principles
are, they’re kind of the secret sauce that makes your work feel good. Squash and stretch is just one of the principles,
and there’s many more that we can’t cover in this lesson. If you really want some in-depth animation
training that will give you the foundation you need to create truly outstanding work,
you’re gonna wanna check out our animation boot camp course. It’s several weeks of intense animation training. You also get access to class-only podcasts,
PDFs, and actual critiques on your work from our experienced teaching assistance. Also, don’t forget, you can sign up for a
free student account so that you can grab the project files from this lesson, as well
as assets from any other lesson on the site. So, let’s go into After Effects and take a
look. Alright, so here is the animation we built
in the previous tutorial, and I’m going to kinda walk through where this started from,
and how it developed, now whenever, you know, I do an expression like this, or like a, this
is actually multiple expressions, whenever I build something like this in After Effects,
it’s not a process that’s linear, and goes from A to B, and I know every step along the
way. I’m basically experimenting and tweaking and
thinking up new things, and then having to go back and revise. So I wanna try to give you guys a little bit
of the sense of that, because if you ever decide to try something like this, it can
be very frustrating, but I want you know, it should be frustrating, that’s just how
this is, it’s it’s, it’s programming, and it’s animation and it’s all wrapped into one,
and it’s, and it can be very complicated when you get into stuff like this, but, if you
just keep bashing your head against the keyboard, eventually you can get something really really
useful. Hopefully that you can share with other people. So, let’s make a new comp, alright, and, let’s
add a circle, and by the way, just so you guys, if you didn’t know this, if you wanna
add a new shape layer, you can select, you know, one of these options here, I picked
the ellipse tool, if you double click it, it creates a shape that fills your comp, alright,
so now if I hit UU, and you just double-tap U, it brings up all of the options for a layer
that are, that have been changed, or are not the default settings, so it’s bringing up
the size of this layer, so now I can just set this to, let’s say, 50 by 50, get a nice
little ball here, we’re good to go. Okay, so first, why don’t we just create a
simple motion path, just to try this out. Alright, so we’re gonna start the ball here,
position, and then we’re gonna go forward one second, and move it up to the top right
corner, we are going to Easy Ease those, quickly come to the curve editor, and, of course,
I am going to need to, actually, I’m gonna use the shortcut method here, which, I normally
don’t do, but just to save time, I’m gonna use the speed graph editor, and I’m just gonna
pull these handles out, which is basically the same as creating a really strong S curve
in the value graph editor. So, if I do a RAM Preview, you’ll see that
I still get that slow acceleration, quick movement in the middle, slow deceleration
at the end, okay? So now if we wanted to be able to just simply,
with one control, figure out the squash and stretch of this, how would we do that, okay? So, here’s the problem I was having. And I’m just gonna make a quick little example
here. So here’s another, another circle for us,
now, if I set the anchor point of that right in the middle, and we just adjust the scale,
alright, so if this circle is moving side to side like this, it would be easy to stretch
it, okay, you could stretch, stretch it on X, squash it on Y, okay? If it was moving up and down, same thing,
you could stretch it on Y, squash it on X, and get the shape you’re looking for. Now, our circle is moving diagonally, it’s
moving, you know, like a 30 degree angle or something, so how do you stretch something
at an angle in After Effects? Well, as I showed you guys in the previous
tutorial, you can go to effects, grab a transform effect, set the anchor point and position
to the center of your layer, and then skew it, okay, and you can adjust the skew axis. So that’s one way to do it, and then you could
sort of come up with a way of skewing it and adjusting the skew axis, now, this is actually
what I tried first, and the problem is, skewing works great when something is at an angle,
but let’s say, you just want the ball to move left to right, well, the skew axis, it’s hard
to tell with a circle, let me actually use a, let me use a rectangle here, or a square,
so you guys’ll be able to see this better. Alright, so if we do that same trick, transform,
put the anchor point right in the middle, put the position right in the middle, and
we skew it, you can see that it’s actually not skewing it the right way, when it’s 90
degrees, you know? It’s sort of, it’s bending it too, so what
we, what we would end up having to do is, you know, right now it looks like it’s bent
sort of, skewed at like a 45 degree angle. Well what if I just wanted it stretched horizontally,
there’s not a great way to do that using skew, so it would have to be some combination of
skew, and then maybe rotation, but even that gets wonky, so it, the skew wasn’t the answer,
and I knew that. So, the way I ended up solving this, was I
realized that you can stack the transform effect, you can have multiple copies of it
on a layer. And that was gonna be the solution, and, and
the way I came up with this is actually very interesting, I took a Flame class at NAB several
years ago, and they showed this trick on a Flame, and it, this is pretty typical, in
my experience anyway, with motion graphics is, you learn something completely unrelated
eight, ten years, you know, in the past, and then one day, you’re on a job, or you’re trying
to figure something out, and your brain solves it for you, and you realize, this information
that was useless 10 years ago has now saved my butt, so the way this works is, what we’re
gonna do, is we are going to rotate the layer, scale it, and then rotate it back, so we’re
actually gonna use three transform effects. So let’s do it on our circle, so we can start
building this rig. So, the first thing we need to do is add a
transform effect, and as I showed you guys, the transform effect it, right now, if I scale
this for example, you can see that it’s doing something weird, right? That’s because it’s scaling it from the anchor
point of the transform effect, not from the anchor point of my layer. The anchor point of transform effect right
now is in the middle of my comp, not where I want it. I want the anchor point in the position of
this effect to always match where my layer is. So, the easy way to do that, is hold option,
click on anchor point, which adds an expression, when you option click, one of these stopwatches
and the values turn red, it gives you an expression box to enter an expression. And actually, all I need to do is type in
position, and actually I need to type in this layer dot position, alright? So, this layer, this is all kind of a shortcut
to just get to the position of this layer. The long way of doing it, would be to pick
whip this layer, and it would say this layer, and I would make a period, and, and if this
isn’t ringing a bell, if this stuff isn’t making a lot of sense to you, you should definitely
go watch my Intro to After Effects Expressions tutorial because it explains a lot of the
basics of how expressions work, and some of the syntax. Then I would come over here to this little
language menu, and you would go to footage, sorry layer, properties, position, semicolon,
there you go, alright? Now you can see when I did that on the anchor
point, it actually moved my layer to the middle, which isn’t what I want. All you have to do is make sure your anchor
point and your position are both set to the layer position. So I’m just gonna copy this, hold option and
click on position, paste that, there we go. So now as my layer moves, you can see up here,
if you watch these numbers up here, those numbers are now moving, and they are matching
now, the position of this layer, so any transforms I do using this effect, will actually work
on the same anchor point as the layer itself, so these are now sort of just a separate set
of position scale rotation keyframes I can add, which is great. So, right now, if we wanna scale this, by
default it’s set to uniform scale, so if we uncheck that, we can now there we go, we can
manipulate the height and the width separately, okay? So you can see, we still have the same problem,
the width only goes left to right, the height only goes up and down. How do we scale it at an angle? Alright, well what we need to do is figure
out what angle this is moving at, alright? Now that was the trickiest part of this whole
thing. So it turns out that there is actually a good
way to figure out the angle a layer is moving in After Effects. And that is to measure two points along that
layer’s path, and then you can measure the angle between those two points. So, I’m gonna show you guys how to do that. So, what we are going to do is put an expression
on the rotation parameter of this transform effect. So I’m gonna option click that, so, what we
need to do is we need to create two variables, point one and point two, and get the position
of this layer at two different points in time. So, point one, is just P1 equals, and I’m
going to do this layer, dot position. Now, I don’t want this layer’s position at
it’s current time, what I wanna do is measure its position a little bit before and a little
bit after the current frame, so that way I’ll know what direction it’s moving. If I know where it’s been and I know where
it’s going, I know what direction it’s going, alright? So, this layer position and then another period,
and there’s a cool expression that I could do a whole tutorial on, it’s called value
at time. So, value at time. What value at time does, is it measures any
property, or almost any property, but at a different time than the current time. And so all you have to do is feed it what
time you actually want to look at, so the current time in After Effects is expressed
by just typing in time, okay? So if I ended the expression there, this would
actually give me the current position, so value at time, time is redundant, it’s just
saying what is the value right now, okay? Well that’s not what I want, what I actually
want is what is the value one frame ago, alright? So the normal way would, to say, what, you
know, the time one frame ago is time minus, and then I’m gonna do another parenthesis
here, one over 24. Now why one over 24? Because After Effects expressions work in
seconds, not in frames, so if I want one frame ago, I actually have to figure out how many
seconds that was, and since I’m in, I’m working at 23-976, or pretty much 24 frames a second,
I have to divide one frame by 24 frames per second. Now, what happens if you guys wanna use this
expression, and you’re not working at 24, what if you’re working at 25, you’re working
in PAL or something, so, that occurred to me, so what I did, was I created a variable
at the top here, FPS, and FPS, I’m gonna set it to, this comp, frame duration. Alright, and just to show you guys that I
had to look that up, if you go down to comp in your expressions menu, you can actually
see that you have frame duration right here. What frame duration tells you is not the frames
per seconds, it’s how long one frame lasts, okay? So, frame duration, in a 24 frames a second
comp, is one divided by 24, so now I can just replace this, with FPS, okay? And the great thing about doing it this way
is that if I change the frame rate of this comp to 30 or 25 or 60 or, if I’m Peter Jackson,
48, then, I don’t have to update my expression, it will automatically do it, and when you’re
writing rigs that you’re gonna share, and that you wanna be, you know, easily reusable,
you wanna try to think ahead to things like this, so let’s move on to P2. P2 is going to be this layer, position, value
at time, now we’re gonna do time plus one frame. Okay, so now we have the position of this
layer, alright, you can see here’s the motion path, so I have the position one frame ago,
which is right about here, and one frame from now, right about here, alright? So now, using some geometry, which might be
a terrifying concept for some of you guys, but you don’t really have to know geometry
because you have something even better, you have Google, and this is exactly how I found
this expression, I suspected I would need geometry for it but I didn’t wanna have to
open a math book, so, I Googled, you know After Effects expressions find angle of layer,
or something like that, I’ll link to the actual page I found, so I can give credit, and I
found an expression that does exactly this, you take two points, and it gives you the
angle between them, and it’s perfect. So what I’m gonna do is just come over here
and I’m gonna copy that, right outta this, and paste it in there, alright, and there’s
some extra stuff on the, on the end here I need to get rid of, alright, so lemme walk
you through the second part of this, so we have point one and point two, what we need
to find is the difference in X and Y, between point one and point two, alright? So what happens next is a variable called
delta is created, delta is the, the result of subtracting point one, and point two, or
subtracting point two’s position from point one’s position. Now, point one and point two both have an
X and a Y value, so you could separate the X and Y out, and subtract each one separately. What this expression does, sub, is it just
does that all in one go for you. Sub can take variables that have more than
one value, like an X and a Y, and it can subtract the Xs and the Ys, all on one thing. Then, once you have that, you use you know,
if you’re like me, you didn’t even remember that this existed, but you have to use an
arc tangent, which is a way of figuring out an angle, based on the length of two sides
of a triangle. You don’t really need to know that, all you
need to know is that, this expression works, and you can copy and paste it in, and you’re
good to go. So, we have the difference between point one
and point two, we get the angle of a, between those two points, using this math arc tangent
expression, then we have to convert the result of that from radians into degrees. And if you’re not familiar with radians, radians
is another way of expressing an angle, it’s based on pi, and when you’re doing math, you
know geometry a lot of times works in radians, not in angles, so, this converts it into degrees,
because this rotation property is expecting degrees, and then, I can erase this little
plus zero thing here, and then this, and then it’s taking the negative of that angle, and
it’s doing something with a percent sign, a 360, I’m not exactly sure, I’d have to look
that up, but, the result of that is now that this, this rotation property actually matches
the angle that this layer is traveling at, and to prove it, if I scale the height, not
the height, the width, you can see that it’s kind of, perpendicular to that, right? So it’s not lining up exactly just yet, but
it’s, you know, you can see that it does orient, and if I add a point here, on this motion
path, you’ll see that this does rotate, and it kind of, sorta follows the motion path,
alright, so when I had this, I knew I was kinda close, but not really close, like, I
had figured out something, but I wasn’t sure what, and so, let’s just get rid of this negative
sign and see if that fixes it, and oh my goodness, look at that, it fixes it, alright? This, I’m walking you guys through my though
process, and sort of, the trials and errors that I went through when I made this, okay? So now we’ve got something kinda useful here. Alright, it’s actually orienting along the
path, all by itself. Alright, so let’s, let’s set this width back
to 100. Now, I’ve realized that, this ball doesn’t
have a lot of detail, and it’s gonna make it kinda hard to tell if this expression is
really working, so before I went too far, I decided to add a stripe to it, and so, you
know, I could show you how to do that with shape layers, actually I’m going to, cause
this is the bonus tutorial, because you guys were nice enough to sign up for the email
list, so I’m gonna do that really quickly. So, what’s great about a shape layer, and
why don’t I just rename this ball, make it kosher, what’s great about shape layers is
you can have multiple shapes within the layer. So, what I’m gonna do is, with this selected,
I’m going to add a rectangular shape here, you can see I’m getting some crazy stuff here,
because this layer is rotated, which is fine with me, so now I have a rectangle, and an
ellipse, and what I need to do is, first, make this rectangle a different color, so
I can, I can see it, so let’s take this, let’s just make it white, okay, and then, I need
to crop it, so it only shows up within that circle, alright, so shape layers work a lot
like Adobe Illustrator, you can actually merge paths the same way and get some cool compound
shapes. So what I’m gonna do is add an empty group,
alright, and I’m gonna call this group stripe, inside of that group, I need my rectangle
path, and I also need a copy of my ellipse path, so I’m gonna duplicate that ellipse
path, and bring it up here. Put it inside of that stripe group. And then what I’m gonna do is, inside of the
stripe group with it selected, I’m gonna add a merge paths, alright? And when I do this, you can have different
modes, so right now it’s set to add, I want intersect, so it’s basically giving me a new
shape, where these two paths intersect, and then that merge paths comes with its own stroke
and fill, I don’t want the stroke, I do want the fill, and I want that fill to be a different
color, and look at that, now we have a white stripe on the ball, it’s all in one layer,
and we’re good to go, okay? And what’s great about this, is that if I
had this ball rotating, it will rotate as it goes along the path, but if it’s being
stretched by the expression, it will stretch, sort of as it’s being rotated, so you see
this is the power of using this transform effect, you can sort of, combine and make
these compound transforms that would be really tricky to do any other way. Alright, so now we have our ball, and our
rotation expression appears to be working, aright? Now here’s, here’s what was throwing me, okay? I don’t actually want the layer to auto-orient,
okay? And now that the stripe is on there, you can
see the problem. If I, let’s say I have a ball, and I want
it to do, just like a bouncing animation, right, just like this, I don’t actually want
that ball to rotate along the path, right, that’s not what balls do, I wanna be able
to control that myself. But, I do want it to stretch along that, okay? So, that left me with a conundrum, alright? So what I realized needed to happen was, I
need to rotate the layer, then scale it so that it’s scaled on the right direction, but
then un-rotate the layer, so that I can actually handle the rotation of the ball, or whatever
the layer is, by myself, and not have the expression do that for me, alright? You know, I want this ball to basically stay
oriented however I tell it, until I change it. So, that’s when I came up with the idea of
separating these transform effects into different parts, so I could control each part separately. So the first part is rotating the layer in
one direction, okay? Now let’s duplicate this. And we’ll call this transform effect scale,
alright, so what I’m gonna do is hit U, so I can open up my expressions here, and I’m
gonna delete this rotation expression, okay? So what I want this second effect to do is
to either scale or squash or stretch this, right? So, it’s, it has been rotated, right? And I know this isn’t gonna make sense until
the next step too, so lemme, lemme just go ahead and add my next rotation, so I have
01 rotate, 02 scale, 03 un-rotate, alright? And so what’s gonna happen is, the first step
rotates it, the second step is gonna stretch it, and it’s gonna stretch it in the wrong
direction, but then it will un-rotate it, and now it will be stretched back in the right
direction, and this, this goes back to, you know, the Flame class I took, and I have to
tell you, professionally, I have never used a Flame, but I learned something useful in
that class, you never know what you’re gonna take away from learning stuff. So, on the un-rotate, this is gonna be a really
simple setup, this rotation, this whole rotation expression here, we can just get rid of. All we need to do, alright, and what I’m gonna
do is I’m gonna hit the Tilde symbol, so if you, if you guys don’t know, the Tilde key,
wherever your mouse is over, when you hit it, it will make that temporarily take up
the whole screen, it’s a very useful shortcut. So I basically want this un-rotate to just,
negate whatever’s going on with this rotate. So if I hit option, click on rotation here,
and I pick whip to this, but then I come to the beginning and add a negative sign, there
we go, then I’m gonna hit Tilde again, so now what’s happening is the ball, is not actually
rotating along the path anymore. However, if I go to now, if I go to 02 scale
and scale it, alright and you can see now we’re getting some interesting stuff, we’re
getting this perpendicular bend, which is not right, however, it is orienting to the
path, right? Now why is it rotating backwards, alright? So this was the problem I ran into. And I realized that what’s probably happening
is, it’s the order that I’m rotating things in, I’m rotating it one way, then I’m rotating
it back the other way, and whatever I’m doing is making it rotate backwards, okay, and you
can even see here, as it comes over this hump, it spins completely the opposite way you would
expect it to. So, what I did was, I came into 01 rotate,
and I just took a look at this rotation expression, and was, and I just, outta curiosity, I thought
“What if I put a minus symbol in front of this?”, and whoa, would you look at that? And now, we’re good to go. Alright and you can see that what’s cool is
it is orienting along that path, however, this stripe in the middle of the ball is staying
flat, it’s not actually changing its angle at all, alright, so if I, if I go into scale
here, and I turn the width down so it’s not so extreme, right, you can see that that layer,
it retains any transforms I have given it, and all it’s doing is stretching along the
path, alright? So, what I’ve basically done is built my own
skew here that can skew that layer at any angle, by rotating it, then scaling it, then
un-rotating it. And it gets its rotation automatically by
choosing the point directly before and directly after the current position of the layer, and
using a little geometry, alright? So now, we, we’ve kind of gotten close, and
when I realized this was working was when I said, “Well, what if this, this ball is
rotating”, right? If I give it its own rotation along this motion
path, and just have it rotate a little bit. You can see that it’s rotating, and as it’s
rotating it’s still stretching, which is just awesome, okay? So now, we actually have the rig, this is
the basis of this rig. The rest of it was just creating some controls. So what I, what I knew was, I wanted a control
for the squash and stretch amount, so I added an expression control, slider control, alright,
and I just called this SS amount, move it up to the top, and I set it to 100, and the
way I rigged this up was, I tied the width, the scale width to this slider, alright? So, that’s really easy, all you gotta do is
option click that, and then drag this up to slider, alright, and so now this slider controls
the squash and stretch amount. Okay, so stretch, squash, okay? Now of course, as I showed you in the previous
tutorial, when I stretch something out, I want it to squash, by an equal amount so that
the total volume of that layer doesn’t change. So I need to put an expression on height,
that looks at the width and adjusts itself accordingly. Alright, so what I did was, I added an expression
to height, and I said W for width, equals, whatever this width is, alright, so now, let’s
make this, let’s make this an easy example, alright? So, if I’m scaling the width to 150, what
does the height need to be? Well, the height needs to be 50, because I’ve
added 50 to the width, I need to subtract 50 from the height. So, I had to kinda figure out in my head,
how do I, how do I figure that out? So, what I basically wanna do is, take the
difference between the normal width, which is 100%, and the changed width, so whatever
that difference is, I need to subtract that from 100, okay? So, if the width is 150, then what that means
is, I have added 50 to the width, I’m gonna subtract 50 from the height, okay? So, the height starts at 100, the same as
the width, alright, and from that I’m going to subtract, and now I need to find the difference,
so the difference is going to be, whatever the width is set to, minus 100. Okay, so there we go, so now when I set the
width to 150, the height goes to 50, okay? If I set the, if I, if I go even longer, then
the width, ya know, if I set the width to 190, the height becomes 10. And an easier way to have done this would
just be subtract whatever the width is from 200, but, ya know, I didn’t think of that
when I was coming up with this, I came up with this, this much sillier equation here,
so, and then the great thing is, if this is less than 100, if it’s 50, then it increases
the height, okay? So this is now gonna totally create this squash
and stretch effect for us. Alright, so now we have a control. And, at that point I said, “Well shoot, “I’m
ready to start animating, and I think, you know, “I think that’s about it, that’s great”,
so as I started animating the ball bounce, I found some issues, alright? So why don’t we, just do a quick little, maybe
one bounce here, okay? So the ball’s gonna start here, I’m gonna
separate the dimensions, alright and I’m just gonna do the Y position first, alright we’ll
go forward 10 frames and it’s gonna fall, and then we’re gonna go forward, let’s say
six frames, and it’s gonna come up about halfway, okay? So, let’s just quickly do the curves for this,
and try and fly through this, alright, so it’s gonna accelerate til it hits the ground,
it’s gonna pop back up, ease into that position, alright, so, just like that. Now, at the same time, I’m going to animate
the X position, so that we actually get a little bit of a bounce, alright? There you go. Perfect, now if we put squash and stretch
on, it’s going to orient itself along the drop now. Now the problem is, when it hits the ground,
it’s gonna squash, and you can see that, because of the way it’s measuring the angle, it’s
looking one frame backwards and one frame forwards, it’s not gonna get the exact angle
right, all the time, it’s gonna be really close, and for most cases, it’s fine. But for extreme cases, like a ball hitting
the floor, or something changing direction drastically really quickly, it’s not gonna
be the right angle, so I needed a way to adjust that, alright? So that’s when I decided to add another expression
slider. So what I did was I duplicated SS amount,
and actually I’m gonna do this a different way now, I’m gonna use a, I’m gonna use an
angle control here, alright? So this angle control, we’re gonna call SS
angle offset, okay? Now what is this going to drive? It is going to drive the initial rotation,
alright? So let’s hit U on this ball, go into the rotation
expression, And basically, all we need to do is leave this part the same, but then add
whatever the value of this offset is, alright? So if the offset’s zero, it’s not gonna effect
it at all. If it’s not zero, it is gonna effect it, and
it’ll be something we can control. So what I’m gonna do is say, plus click and
pick whip, to this, add a semicolon, and we’re good, so now this angle offset is going to
allow me to keyframe and, and sort of, you know, create some nice, flat shapes, alright,
for the ball. Alright, so it’s gonna be zero here, and,
lemme just go ahead and start keyframing this, so, at the beginning of this animation, the
ball is not moving, alright? As it approaches the fastest point of its
animation, which is this frame, it’s gonna stretch out to its maximum stretch, whatever
that’s gonna be, 130 let’s say, alright? When it hits the ground, it will immediately
compress. So, it will now go less than 100, so let’s
say it goes to 80, or it could compress a lot, let’s say 60. Alright, so now the angle’s wrong, so what
I’m gonna do is go back one frame, put a keyframe there, go forward one frame, and adjust this,
until it’s right, okay? And then on the next frame, I’m gonna reset
this, and then it’s gonna stretch out a little bit, as it reaches the fastest point, it’s
gonna stretch out the most, and then as it reaches the top, it’s gonna go back to 100. Okay, so if we RAM Preview this, there we
go, you see we’ve got our nice little squash and stretch bouncing animation going, okay? Now, when I started actually animating this
on my background, which had a floor, that’s when I noticed that when you squash the ball,
it’s squashing from the center point of the ball, when in reality, the ball’s gonna squash
from the bottom of the ball. Wherever it makes contact with the floor,
that’s the anchor point of the squashing. So, I needed to be able to adjust that as
well. So then, I duplicated SS Amount, and I called
it SS Y Offset, let’s turn off keyframes, set this to zero. Alright, so now I need a way, you can see
the rabbit hole that you go down when you start building rigs like this. I needed a way to actually shift the position
of this layer down by a little bit, or up, depending on what it’s doing. So, I decided the easiest way would just be
add another transform effect, so I just duplicated this one here. And let’s name this 04 Y Offset. I’m gonna hit U on this, I’m gonna hit my
Tilde key, you can see we have a lot of expressions going on now, so on the Y offset transform
effect, I’m gonna delete this rotation expression, we don’t need that, what we’re actually going
to change is the position, so what we’re gonna do is, start with whatever the position is,
and then add whatever the Y offset is, to this Y value, alright? So the way to do that, is, we’re gonna adjust
the position expression here, alright, and I’m gonna create a variable, so I’m gonna
say original equals this layer position. So, now what we wanna do, is get this Y offset,
so then we’ll say Y off, I’m just making these variable names up, Y off, is now whatever
this slider’s set to. Alright, so now the value of this position
is going to be we’re gonna open it with brackets, because it’s expecting an X and a Y, and whenever
a property expects two values, you have to bracket them. So we’re gonna open the brackets, and first
it wants the X value. So the X value is going to be the original
position but the, the first value of the original position, which will be the X value. In After Effects, when you have two values,
the first one is is numbered zero, and the second one is numbered one, so it’s kinda
confusing, but you just need to know that when you’re counting in After Effects, you
start from zero. So that first value original bracket, zero,
that’s actually saying, the original layer position, X value, then comma, original one,
so now the Y value, plus Y offset. So, we’re basically taking the original position,
feeding it back but adding a Y offset to the Y value, okay? So now, if I adjust this, this layer, you
know it will still move, if I zoom out so you can see this whole thing, the layer still
moves, exactly as it did before, and it’s still stretches and scales and follows the
motion path, but it is now offset on Y, and this is keyframable, so normally it’s gonna
be at zero, so one frame, on this frame, the Y offset is zero. Go forward one frame, and we’re just gonna
tweak it, so now it’s touching the ground, go forward one frame, and it’s zero, so there
ya go, that’s, that’s how it works, alright? It’s that simple. Alright, and the last thing I added for this
rig, was the ability to have a global, sort of multiplier, so that if you wanted more
or less squash and stretch, you could easily globally apply that. So, let’s duplicate this, call it SS multiplier. Turn off keyframes, and we’ll set this to
one, alright? So, if you multiply something by one, it doesn’t
change, so that’s where we’re gonna start it. So what is this going to effect? This is going to effect, the scale transform,
okay? And really all we need to worry about is the
width, because the height has an expression on it that reacts to the width, alright? So let’s go down here, let’s find that expression,
so here’s scale, and here’s width, okay? So here is my width expression. And this is when I wish I had a, sorry my
height expression. This is when I wish I had a bigger monitor,
or maybe, you know, maybe two monitors, or something like that. Okay, so the width here the width is looking
at the SS amount slider, okay? So really all we need to do is multiply that
by the multiplier, alright? So if the width is set to, you know, 100,
and you multiply it by one, nothing’s gonna change. If you multiply it by two, what’s it gonna
be? It’s gonna be 200. As I’m saying this to you, I’m having the
same revelation I had the other night when I made this expression, that, that actually
isn’t gonna work either, because what I actually want is I want that multiplier to effect just
the change in squash or stretch. So, when that, when this SS amount is set
to 100, this multiplier shouldn’t have any effect on it, because when there’s no squash
or stretch going on, it should be unaffected. But as soon as you get some squash or stretch,
then it will start to be effected. So how’re we gonna do that? Alright, so, again what we, what we really
need to effect is the difference between the default value of 100, and whatever the new
value is, okay? So, what we’re gonna do is we need to measure,
what is the amount of squash and stretch? So let’s make a variable, amount equals this,
the value of the SS amount slider, okay? So then, what we can say is, now we need to
measure the change in that, in the squash and stretch, you know, as opposed to no squash
and stretch. So, because we’re, we’re starting at 100,
if we’re gonna stretch, we’re gonna go up to, say, 150, the change is 50, that’s what
we need to measure. So what we need to do is say the change, so
I’m gonna use D for delta, so D equals the amount minus 100. Alright, so if we have stretched to 150, this
will give us a D of 50. Now I’m going to multiply D times this multiplier,
okay? So now the multiplied amount, I’m just gonna
put mult, mult equals the, mult equals D, times the multiplier. So what we’ve done is we’ve figured out the
change in squash and stretch, and now we’ve multiplied that by, by default by one, doesn’t
change anything, but if I change that to 2, now it’s gonna change twice as much, but if
it’s not changing at all, if it’s still set to 100, nothing will happen, okay? And then what we want to return here is 100
plus that result of mult, okay? So now, when this is set to 100, nothing happens,
okay? And let’s just play this bouncing animation,
so you can see what’s going on, alright? Now in the middle of this bouncing animation,
if I change this to two, it’s gonna stretch twice as much. But if we go back to the beginning, it’s still
completely untouched, okay? That’s cause this multiplier is now only effecting
the change in squash and stretch, okay? So now, you can see it’s a lot more exaggerated. And you can crank this up, alright? If I set it to three, you’re seeing I’m getting
a really thin, kinda goofy, and then when it hits the ground, it really splats, becomes
like a pancake. So it’s too much. And then, this also works if you go less than
one. If you wanna decrease the squash and stretch,
alright? And I guess if you wanted to, you could even
keyframe this, alright? So by default that’s at one, but that is kind
of a global factor for your squash and stretch. Alright, so I think this rig is done, I think
that’s truly, that’s, it seemed a lot simpler this time around cause I knew how to do it. So, there you go, that is how I built this
rig, and if I wanted apply this to anything, all I have to do is copy all of these effects
onto a different layer, alright? So let’s just do a quick test. Just to make sure that this works the way
I think it does, so let’s hide the ball, and let’s make something that’s not as obvious,
let’s make a star. Something like that, okay? And I’m gonna move the anchor point of that
star into the middle, okay? And I’m just gonna do a quick quick little
animations here, so it’s gonna start here, gonna go forward, let’s go 20 frames, it’s
gonna come over here. You can see the anchor point’s all messed
up, so why don’t we fix that? There we go. Alright, so position, go forward 20 frames,
move it, then we’ll go another 20 frames, come back the other way, I’m having all kinds
of trouble here, people, here we go, alright. And then we’ll, we’ll just use the default
Easy Ease on those, save ourselves some time, alright? So here’s what our star’s doing, okay? And now I’m gonna come here, I’m gonna disable
all of these stopwatches, so we’re kind of at the default values here, I’m just gonna
select all of these and copy them onto the star, okay? So we come here, put a keyframe on squash
and stretch amount, as it gets to the middle it’s gonna stretch out, and you can see it
is stretching out in the right direction, and then as it comes here, I’m gonna have
it, I’m actually gonna have it squash a little bit. Just a little, cause it’s kind of decelerating,
and then it’s gonna come back, stretch out again, and as it gets to the end, it’s gonna
squash, just a little, and then it’s gonna reset back to 100. Alright, so just that quick, you’ve got this
thing squashing and stretching and, and reacting in the direction it’s moving. And, especially with something, you know,
with like a complex contour, like a star, this would be very hard to do, without a rig
like this, you’d have to, either animate masks, or you’d have to try and get it to work with
the skew, but then, let’s say you had the star move straight up and down, or left and
right, it wouldn’t work, so, with this rig, this makes it very, very simple. So there you go. Thank you guys so much, and I will talk to
you soon. Thank you so much for watching, I hope this
lesson gave you a good understanding of the animation principle of squash and stretch. If you wanna know more about how to use the
principles of animation to really take your work to the next level, make sure you check
out our animation boot camp course, for an in-depth learning experience, focused on teaching
you the craft of animation. If you have any questions or thoughts about
this lesson, let us know, and we’d love to hear from you, if you use this technique on
a project so, give us a shout on Twitter, @schoolofmotion, and show us your work. Thanks again, and I’ll see you next time.

19 Replies to “Squash and Stretch in After Effects”

  1. This tutorial is awesome, thank you so much for your work. I'm just wondering if it's possible to control the amount of squash and stretch by connecting it to the speed of the ball? I tried a bit myself, but after effects got some issues when you seperate the dimensions of the position.

  2. Thanks for this tutorial.
    I tried but when I write the expression
    fps=thisComp.frameDuration;
    p1=thisLayer.position.valueAtTime(time-fps);
    p2=thisLayer.position.valueAtTime(time+fps);
    in rotation line it says "error at line 0 in property 'rotation' of layer 1 (shape layer) in comp 'comp 1' expression result must be dimension 1, not 2."

    There is no project file at the link I create own file maybe because of that?

    Will appreciate if can help.

  3. Joey! You have obviously taken this to another level and have undoubtedly been doing this for longer than I can imagine,you must sleep in a blanket of code! Thank you so so much

  4. Thank me later:

    fps=thisComp.frameDuration;
    p1=thisLayer.position.valueAtTime(time-fps);
    p2=thisLayer.position.valueAtTime(time+fps);
    delta=sub(p1, p2);
    angle=Math.atan2(delta[1], delta[0]);
    ang = radians_to_degrees(angle);
    -(ang)%360

  5. Thank you for this tutorial, it was useful to get me thinking about this in a different way. I found that parenting the layer with all of the expressions to another layer will break the values unfortunately

  6. (15:15) if you want velocity sir, why not simply ask ae to measure layer's velocity? ^_^

    velocity = thisLayer.transform.position.velocity;
    // just like position has x: position[0] and y: position[1] component, velocity has them as well: velocity[0] and velocity[1] respectively.
    angleInRadians = Math.atan2( velocity[1], velocity[0] );
    angleInDegrees = 180 * angleInRadians / Math.PI;
    // Math.atan2 (converted to degrees as done above) returns angle values between -180 degrees and 180 degrees. whenever layer moves (even so slightly) down these angles are positive, and whenever layer moves (even so slightly) up these angles are negative. -0/0 degrees both mean that the layer moves to the right, 90 degrees means that the layer moves down, -90 degrees means that the layer moves up, -180/180 degrees both mean that the layer moves to the left.
    // if one doesn't like this positive negative business and likes to work with angles between 0 and 360 degrees this can be fixed as follows:
    angleInDegrees = (angleInDegrees > 0) ? angleInDegrees : angleInDegrees + 360;
    // which in plain english means, that if the angle is positive then we leave it be, but if it's not then we add 360 to it.

  7. (17:28) nope. the line -(ang)%360; doesn't do anything useful to you except flipping the sign of your angle for no reason other than confusion. if anything this could only cause you some difficult to catch problems down the road. so please sir don't teach others to mindlessly follow you with this practice.
    as i've written before, the atan2 function (after the conversion to degrees) returns values between -180degrees and 180degrees, which can be cumbersome to work with because in after effects this scale goes like this:

    0deg meaning hour 3 on the clock,
    30deg meaning hour 4 on the clock,
    …,
    150deg meaning hour 8 on the clock,
    180deg = -180deg meaning hour 9 on the clock,
    -150deg meaning hour 10 on the clock,
    …,
    -30deg meaning hour 2 on the clock,
    -0deg = 0deg meaning hour 3 on the clock,

    whereas what we usually like to think in is the scale that goes like this:

    0deg meaning hour 3 on the clock,

    30deg meaning hour 4 on the clock,

    …,

    150deg meaning hour 8 on the clock,

    180deg meaning hour 9 on the clock,

    210deg meaning hour 10 on the clock,

    …,

    330deg meaning hour 2 on the clock,

    360deg = 0deg meaning hour 3 on the clock,

    which is what you tried to accomplish with the said -(ang)%360; line.
    use (ang > 0) ? ang : ang + 360; instead.

  8. I'm feeling lucky that these incredible tutors from School of motion are my professors.. You help me a lot as I've finally got the nerve to change my career from mechanical engineering to Art as I've always dreamed of.. I would like to thank you all for your effort and to request the link for your account on behance if you have any. It would also be very kind of you if you have the time to have a look on my humble account https://www.behance.net/mechanicalf0a8 as it's my first month in the field and expert critique would be very appreciated. Thank you and keep it up <3

  9. Thank you Joey, fun tutorial! 😀

    To anyone struggling to get the angle to work, I think that Adobe has updated their expressions code so that radians_to_degrees creates an error ("Error: ReferenceError: radians_to_degrees is not defined"). However, I found that there is one called radiansToDegrees in the expression library, and that solved it for me 🙂

    fps=thisComp.frameDuration;
    p1=thisLayer.position.valueAtTime(time-fps);
    p2=thisLayer.position.valueAtTime(time+fps);
    delta=sub(p1, p2);
    angle=Math.atan2(delta[1], delta[0]);
    ang = radiansToDegrees(angle);
    -(ang)%360

    Expression library:
    https://helpx.adobe.com/after-effects/using/expression-language-reference.html

  10. I'm having trouble with the expression part too. I made the update from " radians_to_degrees" as shown in the video to "radiansToDegrees" as some have already suggested and it still won't follow the angle of the path. So is there a reason the following doesn't work?
    fps=thisComp.frameDuration;

    p1=thisLayer.position.valueAtTime(time-fps);

    p2=thisLayer.position.valueAtTime(time+fps);

    delta=sub(p1, p2);

    angle=Math.atan2(delta[1], delta[0]);

    ang = radiansToDegrees(angle);

    (ang)%360

Leave a Reply

Your email address will not be published. Required fields are marked *