Walking When Moving
Right now, our avatar is constantly walking—even when we’re not controlling it with our controls from Chapter 4, Project: Moving Avatars. Let’s fix this problem.
First, let’s add a way to track the direction in which the avatar is moving. Add four more lines above the animate() function, starting with the value of isMovingRight:
| var clock = new THREE.Clock(); |
| var isCartwheeling = false; |
| var isFlipping = false; |
| var isMovingRight = false; |
| var isMovingLeft = false; |
| var isMovingForward = false |
| var isMovingBack = false; |
That code says that our avatar is not moving at first. Until something happens, our avatar is not moving right, left, forward, or back—it is false that the avatar is moving ...
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.