Question about code in chapter 4

Hello need help with the code in chapter 4. I tried to lrt the acvatar flipping with the button C but my avatar won’t flip. It makes a Cartwheel. here is the code:

Thanks

Looks like the forum didn’t accept your code for some reason. Sorry about that. Can you re-post, following these instructions?

Also, does the JavaScript console (as described in chapter 2) show anything that might suggest a problem?

-Chris

Nice hat on the avatar :smile:

There is just a tiny typo in the code causing the problem. On line 62, one of the rotation properties is misspelled as ‘rotaion’:

     avatar.rotation.z = avatar.rotaion.z + 0.05;

Just fix that to:

     avatar.rotation.z = avatar.rotation.z + 0.05;

And everything should be working perfectly!

If that doesn’t help or if you have any other questions – please ask :grin:

-Chris

Ok, Thank you very much. it works perfectly now .

Hi,
I think now it isn’t a faily spelled word. The console says nothing, but it won’t make trees
Here is the code:

https://www.code3dgames.com/3de/#B/nVZZc+JGEH7nV/TygpwFAalQTvnYKsJieytedguT2ryOpQZNLDTKzIAMLv779owOJAQuEkpcfX1fH+rRzbPwN59uuvarcaM8yWMNSnq3za4OJKL7j2qSPlUUFp8aAN0uzAKEpvIwwiZwBUmAEkHp1XwOPAKxkrBgS4SEhyEELI4xuiLHNZNgneAWIkxg9jAdj90nI3EurjODecg06d/M91PAfB4trkDLFe5yi5AvAl0JMVw+c4z0o1E4rSTgGltt6Lm/26gW0mW+71hPkpWS8IinZFkWhKwQFeggyyZnzVSMnp4yzQUBJzzyReLyKEL5g/s6gG5F9oAGJ6ebIlT4fkdpA/I1jqzWuRy0yyBt6NPVo5fNIA3hxkJxUkbulqINer1qcqlRNTuJkU+tkU3wJUuyFE12GSmbrYi0SFP2qO9Fp3LfCvMf+Hz/OM00zhuLNGchZyprkWWbO7oK9RPfolOrV/tIuayrL7zVkjrpmrF07eD4o4CHvlME9cVyHKIxKlL9JXvB02w4ncHo2+cvk3v4NiHOY5iM/57B45fJuDAjpyxFg1KdxdhM8j2KJWq5cfpZ/W0bxfqgFl9RBRMhlyz8yjRKKsR+itmaaVY3dwxiO411MJuphxVmMQIW+e+xG/TK1tIU8eHQxYKaQGXQwnQ/UdQqp9Mf9OiuoctapYQst8KhDBji/Ey83LIKdxItNy+DzYXQ/7EWd4culpsJVKuFMT2oxSUx6/T7g1PVMC6H1TgPMbesAr6DlzuU4RRt1XyNZmCjTcjNPbKfXrtCso/f/ucg69Uz1nOy8OWkSnSNh5WZH9Uke0Bs9jnSNV9FnlHDkr3gjNbPUDuvbdhewBtpMwpyFb3UOVg9lKS1ApgBM+9f6TZu18xNkD+Y4l6R9JsnQiGvoKXoNIlYa3eROVm2BR0RnyQD7+ySwZ7EmTTmQqLSC7OUj3AhHvvqmjXWvxwUOlOytBsiLjwqykpjqOQdcwRtre2O3qV+mKMmb1lJ3DkuvhzYSc6PrrLDgcrQoe09EUmb5lkkp06n6tnUsE3gasSkpucOpJ4vKPk5CxVe58q7kMdxVVFMGov4kkrtZCMm8d8VVXlopaS/kwTuZEZp6fgcnCpgPp753EuhWXEy12Uf6VmklzZntw+YkzwZ7PVIsNdasOJkTH849khpQ/E4YKyKnK9NAYtTlgZkvLYPTkqTk3RaL7ihczmipydF0f7EzWf6d1EuX0nuoHFO6aebxTe7wkpd88eQNLmmiltoDaUUySPts9ZFnlkxh6VsS7IODI5HmZotfHaYj6fC/BUfibE9EmN7moqpxdlRjjGheo4oQG2oP1Qlx/zurF9p3j/s/103do3iCf4n

Sorry, that i am asking so a lot.
Thanks

No worries – keep asking questions!

You’ve got the makeTreeAt() function done perfectly except that you forgot the last line. Add scene.add(trunk) (as shown below) and you’ll see the trees as expected:

  function makeTreeAt(x, z) {
    var trunk = new THREE.Mesh(
      new THREE.CylinderGeometry(50, 50, 200),
      new THREE.MeshBasicMaterial({color: 'sienna'})
      );
      var top = new THREE.Mesh(
        new THREE.SphereGeometry(150),
        new THREE.MeshBasicMaterial({color: 'forestgreen'})
      );
      top.position.y = 175;
      trunk.add(top);
      
      trunk.position.set(x, -75, z);
      scene.add(trunk);
  }

There were no errors, so nothing showed up in the JavaScript console – so nice work! If you run into anything else, please ask :slight_smile:

-Chris

Thank you
sorry for the many questions

You are quite welcome.

Questions are good. Many questions are great – especially if you keep trying to find the problem with the JavaScript console. Keep up the good work :+1:

-Chris

1 Like

Hello,
I have another problem :disappointed:
I don’t know why but my avatar is away.
Here the Code:

https://www.code3dgames.com/3de/#B/nVdbc+I2FH7Pr9DygumCgbZMOrnsDCUk2WmWdAid7auwD1gbY7mSwIEM/71Hsi3bGDK0jMPlXL9z0TnKzZz72y83XfNxcSM9wWJFpPBuG10VCAD3h2wgP2VYiS8XhHS7ZBYAaUgPImgQJkkSgAAi1XqxICwifC3Ikq6AJCwMSUDjGKIrVNxQQYwSuSURJGT2OB2P3RdNcVrXmcAipAr57/rzJaA+i5ZXRIk17HOJkC0DVTExXM0ZROpJM5xmEjAFzTbpub8Zq8alS33fMZpIKwXhIU5BsyjQswSQRAVZNDlqKmPw1JQqxtFxwiKfJy6LIhDfma8C0q3QHkH7yeGmHip4/wRhDLINjAzXuRy0y07apI9PD18mgtSEG3PJkBm5O7Q26PWqwaVC1egERD6WRjSIL2iShaijy0CZaHmkeBqyh3W3lcp1K8i/w/zhaZpxnHcaKUZDRmVWIoM2V3QlqBe2A6eWr/aRdBlVn3vrFVbS1W3pmsbxRwELfcca9flqHIIWsqH+lL3Iy2w4nZHR893XyQN5niDmMZmM/56Rp6+TsRVDpSzEFRWvBwE+z39gEX65cw5aJxU1xEJfo6z2cqxPwgPwFSixdfpZ/Uwb8M2Bq28ggwkXKxp+owoEJrI4BXRDFa2LO9pjO7VlZFNY1fqXEQY08j9COOjlCqbkuhCPhyrGsTZUdmxFi67Ecjud/qCHJw8fI5WGYeBZhbLDEBZn+sslq+5OesvFy84WnKv/mIv7QxWDTRuq5UKLHuTiEpF1+v3BqWxolcNsnOcxl6w6/MBfrpC7K7GqfWNmNI7sfEZnKEbbkOkDWLS2mU/Z26//s8vVeg71YI37crQlsFrD0PSXavQ9gmiK4PFZrCNPs/GUvMIMZ9tQOW9tsmuRd+RmEMQ6eq1jMHxSotYSoDtP//2MZ7xdE9dGfqeSeTbod4+HXFyRpsRVFdHmvpUpGbQWDo9PgiEfDJpBAeJMGAsuQKqlnvhHsCCOIrt6xvUvB5anU5ZWg8dWo8KsFAZT3tH7bWdli7FqxA19n02tUq30jsvLWSJ3jpMvB6b9851ZVjhg2UcvjwlP2tjxPDm1HKur8cKUickRFQqvPYBdscT0LGgo4Tpn3ocsjqsM24s0YisshpM1oYB/1liHoaEi/16gcycTShPGFsSpOswbOD8ZgitqLwZ12me8CvXS8u0LgznIk8bejhh7qxmzizn94pjatkkxVVDKxnytE2iXPDbAeGPubVKhknCar7DFa0GElzeJ1v6A7R3+apXTV6I7oJVT+Ons8fU0MVRX/9Agdawp45Y0h0Lw5AlHYbOVb07bqTraOq1DBsetTPUAP9vM51Nm/oqP2NgdsbE7DUXn4mwrx5BgPkdooNbUn6qUY3r3Rq/U75+KX9cX+wv7D8S/

Thanks for the much help.
The book is very cool :+1:

Glad you’re enjoying the book! You’re definitely asking good questions, so keep at it.

There are two minor problems in the code. Be sure to go back and reread in the book why these lines are the way they are. The first is line 30. Currently it looks like:

  marker.add(camera);

Instead of adding the camera to the marker, we want to add the avatar to the marker:

 marker.add(avatar);

I’m not sure if the other problem is really a problem – you just might not have gotten to it yet. Currently, line 53 add the camera to the avatar:

  avatar.add(camera);

Instead of adding the camera to the avatar, we want to add it to the marker:

 marker.add(camera);

Like I said, you probably haven’t gotten here yet, but don’t forget to make that change before moving on.

If you have any other questions, keep asking!

-Chris

Hello,
I understand the book but in this case is understand it so to add it the other way
and one question did you programm this website self?

Are you asking about this forum or the 3DE site?

I did not program this forum – it’s forum software named Discourse.

I did program the 3DE site, though parts of 3DE come from code libraries that other people have written.

-Chris

1 Like