CHAPTER 8
Project: Turning Our Avatar
We’re nearly finished animating our avatar. In Chapter 4, Project: Moving
Avatars, on page 35, we learned how to make our avatar move. In Chapter
6, Project: Moving Hands and Feet, on page 59, we made the avatar look like
it was walking. Now we need to make it look as though it can turn when we
switch directions. Turning, or rotating, is not new to us—we already make
the avatar turn when flipping and cartwheeling. But this time we want to
make our avatar face a particular direction.
9.1 Getting Started
If it’s not already open in the ICE Code Editor, open the project that we named
My Avatar: Moving Hands and Feet (from Project: Moving Hands and Feet). Make a
copy of it by clicking the menu button and choosing MakeaCopy from the menu.
Name the project My Avatar: Turning and click the Save button.
8.2 Facing the Proper Direction
Getting the avatar to face the proper direction is fairly easy—especially with
all that we already know. Just as we did when we added the walking motion
of the hands and feet, we’ll write a new function to turn our avatar. We’ll call
this function turn(), so let’s add a call to this function in the animate() function.
functionanimate() {
requestAnimationFrame(animate);
walk();
turn();
acrobatics();
renderer.render(scene, camera);
}
animate();
When you’re done with this chapter, you will
- Know even more fun math for 3D program-
ming - Know how to rotate something to face a
specific direction - Be able to make smooth animations
Prepared exclusively for Michael Powell report erratum • discuss