Making the ball bounce
How should a ball bounce? Unlike the magical color-changing cube we animated in the previous chapter, a bouncing ball is something you’ve seen in real life. This makes it a bit more challenging – we already have an idea in our mind as to what a bouncing ball ought to look like, so there are right and wrong ways to achieve this effect.
For guidance, we’ll look to the laws of physics, which preside over the motion of things such as bouncing balls. Since we’re animators and not physicists, these laws are just guidelines we can take or leave – this particular ball, for instance, will eventually be made to bounce and roll forever. Nevertheless, knowing a little physics will help us anticipate the forces at play and determine the best interpolation modes for our F-curves.
According to Newton’s first law, an object in motion shall remain in motion unless acted upon by an external force. What this means is that force is required to change the direction or velocity of an object. So, what are the forces at work in a bouncing ball?
The most obvious force we want to simulate is gravity, which pulls things down. The second, less obvious force is that of our imaginary floor that (if we assume it’s level) will force the ball back upward each time there’s an impact. So, one force for down, and another for up. Up and down – hey, those are both on one axis. How convenient! To simulate these two forces acting on the ball, we’ll do our fanciest keying on the Z Location F-curve. What about the other two F-curves, then?
Linear interpolation for objects in mid-air
If you’ve played or watched any sport with a ball in it, you’ll notice that a kicked or thrown ball will have a constant rate of rotation and horizontal movement while it remains in mid-air. Besides a bird or a strong gust of wind, nothing in the air is going to significantly change how fast the ball spins or travels in a horizontal direction. What this means for us is that the X Location and Y Euler Rotation F-curves of our ball should show linear movement, without any change in speed.
The ideal interpolation mode for this is, of course, Linear:
- Select both keyframes on frame
10
for the ball’s X Location and Y Euler Rotation animation channels. - Set the keyframe interpolation to Linear.
This might be one of the least exciting interpolation modes to use, but it’s the one that makes the most sense for these particular F-curves.
Figure 2.14: A Linear F-curve segment
Our animation still has those sudden changes in speed at frames 10
and 90
, but we’ll address that at the end. Let’s get to the bouncing!
Adding bouncing keyframes in the Graph Editor
Whereas keying the X Location and Y Euler Rotation animation channels of the ball was straightforward (no pun intended), our Z Location F-curve is going to look completely different. We’ll also need to carefully select some different modes of interpolation to simulate the physical forces at play.
As if there weren’t enough methods in Blender for inserting keyframes already, we’re also going to use this section as an example of how we can animate using only the Graph Editor. Without leaving this editor, we’ll add the keyframes needed for a single bounce and then determine their interpolation.
Important note
You’ll need to ensure that Z Location is unlocked and unhidden for this next part. Remember how to toggle the visibility and edit-protection of F-curves? You might also want to hide or lock the other two channels and maybe disable Normalize, but that’s up to you. From here on out, you’re in charge of your view and the display settings in the Graph Editor that we’ve learned so far.
Inserting keyframes within the Graph Editor
A single bounce will require three key values on the Z Location F-curve – the ball’s low point on the grid floor, the high point of its bounce, and then its low point on the floor once more. This will require three keyframes (two if you use Bezier handles, but you don’t know that yet). These keyframes will go on frames 10
, 20
, and 30
, giving us a nice 20-frame bounce.
We’ve already got our first Z Location keyframe; let’s add the second one now:
- Select the Z Location channel.
- Go to frame
20
. - With your mouse cursor in the Graph Editor, press the I key. Note that this brings up a different menu than the one we used in the previous chapter:
Figure 2.15: The menu to insert keyframes in the Graph Editor
- From the menu, choose Only Selected Channels.
By using this menu to insert a keyframe on just the Z Location F-curve, we’ve added just one single keyframe, not a set of three or six as we had been doing before. This has zero effect on our other two F-curves. Why bother inserting extra keyframes where we don’t need them?
This second keyframe can be used to determine the high point of the ball’s bounce. Right now, of course, it’s still on the floor...
Editing the value of keyframes
We’re going to use this opportunity to move up the keyframe we’ve just made so that you can experience editing the value of a keyframe directly in the Graph Editor. We’re going to move our second keyframe up by 1 meter, which just happens to be a nice-looking height for a 20-frame bounce.
Let’s do it now:
- Select the Z Location keyframe on frame
20
. - Press G and Y and move it up by approximately
1
unit.
As you move that keyframe up on the Graph Editor’s Y axis, pay attention to what happens in the 3D Viewport:
Figure 2.16: Moving the keyframe up on frame 20
If you’re still on frame 20
, you can see the ball move upward! By editing the value of the Z Location keyframe, we’re affecting the ball’s location on the Z axis from within the Graph Editor!
Tip
Changes made in the Graph Editor are immediately reflected in other areas according to how they affect the F-curve at the current frame. You don’t have to go to the same frame as a keyframe to edit it, but it’s often a good idea.
We’re halfway to completing our bounce, now that we have a Z Location F-curve that shows a definite change. The ball starts on the floor, and then it goes up – next, we just need to get the ball back down.
Duplicating keyframes in the Graph Editor
Anything that goes up will have to come down. Making that happen to the ball will be the job of our third Z Location keyframe in this sequence, which we are presently to add.
What should the value (i.e., the Y axis position) of this keyframe be? The answer is the same value as the first keyframe, whereupon the ball is touching the floor. Our imaginary floor is flat and hasn’t gone anywhere since the ball left it after frame 10
. The value for that keyframe happens to be 0.35
. That was easy. Figuring out the time (i.e., the X axis position) of this keyframe isn’t hard either. If it took 10 frames for the ball to bounce up 1 meter, it should take another 10 frames to fall back down to its original height. 10 frames after frame 20 would put our keyframe on frame 30
.
We know exactly where our third keyframe needs to go, and there are plenty of ways to put it there in Blender. We could, for instance, simply insert another keyframe on frame 10
and move it down. Nothing wrong with that, but there’s another way that’s even faster – we can simply duplicate the keyframe on frame 10
and move it over to frame 30
. It’s already at exactly the right height!
You already know how to move and duplicate keyframes in the Timeline. The method for doing so in the Graph Editor is the same, but with one additional step:
- Select the Z Location keyframe on frame
10
. - Press Shift + D to duplicate the selected keyframe.
- Press X.
- Move the duplicate keyframe to frame
30
.
Figure 2.17: Three keyframes forming a “hump” in the Z Location F-curve
Did you catch that extra step I mentioned? We had to press X. This was for the same reason we had to press Y after grabbing a keyframe to move it up. Keyframes in the Graph Editor can be moved along two axes instead of just one – axes which map to completely different things. When we move keyframes left and right without locking them on the X axis, they can move up or down just a little, changing their value. Even a small difference in the value of this third keyframe could give us a strange result later on.
Important note
For the example in the previous paragraph, we will often want to lock our transformations to either the X or Y axis when moving keyframes in the Graph Editor. Just remember to press X or Y!
The first three keyframes on the Z Location channel now make the ball go up and come back down. Take a look at the shape of the F-curve, though – does this “hump” count as a bounce? Play the animation and see for yourself.
Tip
If you view your animation in the 3D Viewport from the front, you can watch how the ball’s path perfectly mimics the shape of the Z Location F-curve as it moves from left to right.
If you think that’s good enough, you must live underwater. Here on dry land, a ball does not bounce in a sine-wave motion. It does not steadily accelerate upward after leaving the floor, nor does it slow down right before touching it again. To complete this bounce, we’re going to need to use what we learned earlier about interpolation and easing.
Proper interpolation and easing for a bouncing ball
How can we improve the motion of this “bounce”? The issue can’t be the position of our three Z Location keyframes in the Graph Editor; we know that the ball has to start on the floor, we know it needs to reach a high point, and then we know it should come back down in the same amount of time. The frames and values of these keyframes are fine. What’s wrong is the shape of the F-curve between those keyframes. We simply can’t ignore interpolation!
So, what kind of interpolation do we need here? Can you pick it out from the Set Keyframe Interpolation menu? Don’t say Bounce – that’s cheating, and besides, you’ll see it gives us little control over things such as the height, rate, and number of bounces.
Remember, we’re trying to simulate gravity here! Gravity is observed as a constant downward acceleration, acceleration is the rate of change of velocity, and velocity is the rate of change of displacement (i.e., location). The kind of line we need to create, then, has a rate of change which itself has a constant rate of change.
I’ll spare you the rest of this physics lesson. What this essentially means is that we need a slope with a quadratic function. Let’s find that interpolation mode now:
- Select the first two Z Location keyframes on frames
10
and20
. - Set Keyframe Interpolation to Quadratic.
This gets us halfway there, but the first half of the bounce is still wrong:
Figure 2.18: A less-than-ideal, shark-fin-shaped F-curve segment
It eases in, and we need the segment to do the opposite of that. Good thing we know how to change easing types:
- Select the first Z Location keyframe on frame
10
. - Set Keyframe Easing Type to Ease Out.
Now we have a bounce!
Figure 2.19: A proper bounce in the Z Location F-curve
There’s just one small matter left – the ball only bounces once.