3D Game Programming

(C. Jardin) #1

CHAPTER 6


Project: Moving Hands and Feet


When we last saw our avatar in Chapter 4, Project: Moving Avatars, on page
35 , it was moving around pretty well, but it was a little stiff. Even when the
body moved, the hands and the feet stayed still. In this chapter we’ll make
our avatar more lively.

7.1 Getting Started


In this chapter we’re again building on work from previous chapters. Since
we did so much work to get the avatar moving in Project: Moving Avatars, let’s
make a copy of that project to work on in this chapter.

If it’s not already open in the ICE Code Editor, open the project that we named
My Avatar: Keyboard Controls. Make a copy of it by clicking the menu button and
choosing Make a Copy from the menu.

Name the project My Avatar: Moving Hands and Feet and click the Save button.


With that, we’re ready to start adding life to our avatar!


6.2 Moving a Hand


Let’s start with a hand. Recall from previous chapters that hands and feet
are just balls that stick out from the head. We built the right hand in Java-
Script with this:

varright_hand =newTHREE.Mesh(hand, cover);
right_hand.position.set(-150, 0, 0);
avatar.add(right_hand);

As you know, the three numbers we use to set the position of the hand are
the X position (left/right), the Y position (up/down), and the Z position
(in/out). In the case of the right hand, we have placed it –150 from the center
of the avatar.

When you’re done with this chapter, you will


  • Understand some important math for 3D
    games

  • Know how to swing objects back and forth

  • Have an avatar that looks like it’s walking


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf