Unable to turn my avartar,chapter 8

It’s a problem with the chapter 8.
I cannot make my avatar turn around while walking.it was ok with the preceeding chapters, no problems, everything just fine. But when it comes to chapter 8, the problem arises. If I press left/right, the avatar just move but cannot turn, I don’t know why?That’s my code until now:
https://www.code3dgames.com/3de/
Thanks for helping.

I’ll need to see your code in order to help you. Unfortunately, you shared a link to the 3DE code editor, not to your code.

To share your code, either use the share option from the menu in 3DE or copy and paste your code directly into your reply. The share option is less error prone. If you prefer copy & paste, be sure to paste it between 3 backtick lines:

Explain how your code is misbehaving...

```    
// Paste your code here
```

Include any more information that you like here...

Once you share the code, we ought to be able to figure out the problem relatively quickly.

-Chris

Thank you for your replay. I just change the link. Thanks for your help.

https://www.code3dgames.com/3de/#B/pVhbU9s4FH7vr1B5idM6xulOpjtQd4aG0HZK0w6kw74KW8EqjuWVFEzC5L/vkSzb8q2lsyFDnHM+neunI8G7Wxbt3r871h8v3omQ00wiwcPg6FjGnBDvpzgCfaHoIHJC0n7E+xcIHR+jVUzQkQhJSo4QFSiPCSdIyO16jWiK2JajO7whKKdJgmKcZSQ9gYUPmCO9CAUoJTlafbpaLLxrJXHGpwawTrAE/ZP6vI5xRNO7EyT5lhxKRELvYtkwcba5pSSVl0rhjPKYSjJyke/9ra1qlx6OIkevBJmVRAhxcmyyAM+CEIFkbLIpo8YiI6G8wpIycJzTNGK5R9OU8BsayRgdN2SfiPJThlt4aMT7nXBtkD6QudY6b2eu7cRFU3j78NIZFCa8jAkKytTbg7WZ7yuVnQsnaQSN4Eco4jg3CalcTAg6N5ZKViQYAg+qvpRrG3HekNuPl1dG4zzhVFKcUCxMQ3Rs5UJPEHlN98TpVMftKY5eGrFwu4G+eYqmnqZJNI9pEjmV0YhtFglRoKptr8wLXa/OrlZo/u388/Ij+raEmBdoufhnhS4/LxcVzOS3wfye8KDO7dvtT6j2X+dOiyMFUAuLt1qtArTWXmeK8B8J2xDJdw40yn3ju9NZReKQPYAzq5JfiYiXjG9w8hVLwqGMNePxA5bYDk2B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quJ/5KqbkT4su35KN9DWOXQGtY/4l83vp91lF7DMOvtf1s+nqKber3m3zSrW/ch6Ofcj+1+M679pDHJn6NLST4Hh28pQJweuMIf6CCt/vaj+7fIf

The problem is on line 104, the isWalking() if-statement:

  function turn(){
    if(isMovingRight) direction=Math.PI/2;
    if(isMovingLeft) direction=-Math.PI/2;
    if(isMovingForward) direction=Math.PI;
    if(isMovingBack) direction=0;
    if(isWalking()) direction=0;
    
    if(direction==lastDirection) return;
    lastDirection=direction;
    
    var tween=new TWEEN.Tween(avatar.rotation);
    tween.to({y:direction},500);
    tween.start();
  }

That line should set the direction to 0 if the avatar is not moving. Right now, the code sets the direction to 0 when the avatar is moving. So if the avatar is moving to the right, left, back, or forward, the code faces the avatar forward.

Just change that line to the following to fix it:

    if(!isWalking()) direction=0;

Other than missing a single !, the code looks good!

-Chris

I really appreciate your help. That’s it, I forgot it. And I just want to say the book is very engaging and easy to understand. It is amazing. Thank you for bringing us such a wonderful book. I cannot wait to continue reading the followings. Have a nice day.
:rose::rose::rose: