Swinging Hands and Feet Together

How did it work? Were you able to get all of the hands and feet swinging back and forth? Did you run into any problems?

If you tried moving the hands and feet in the same way, you might have noticed that our avatar is moving awfully strangely. Both feet and both hands move forward at the same time. And then both feet and both hands swing back at the same time. No one walks like that in real life.

When you walk, one foot is in front and the other is behind. In avatar terms, one foot is in the positive Z direction while the other is in the negative Z direction:

 
var​ position = Math.sin(clock.getElapsedTime()*5) * 50;
 
right_foot.position.z = -position;
 
left_foot.position.z = position;

People also usually move ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.