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 add another function to animate turning our avatar.

Let’s start by going to the list of things that control our avatar.

​ ​var​ clock = ​new​ THREE.Clock();
​ ​var​ isCartwheeling = ​false​;
​ ​var​ isFlipping = ​false​;
​ ​var​ isMovingRight = ​false​;
​ ​var​ isMovingLeft = ​false​;
​ ​var​ isMovingForward = ​false​;
​ ​var​ isMovingBack = ​false​;

At the bottom of that list, add direction and lastDirection.

​ ​var​ direction;
​ ​var​ lastDirection; ...

Get 3D Game Programming for Kids, 2nd Edition 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.