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 ...
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.