Fruit Hunt: Chapter 11

Hello,
The avatar will not jumping or collect coins; When we went to inspect we fixed the problems present. I did get it to work once but it will not work again. Line 208 was a problem said p2 is not defined. Line 201 said that the ; was not present and line 304. if (code == ‘Space’) jump(); said it was not defined. Please help.

Sharon Deutscher

Without seeing your code, I can only guess. If you could share the code, I would be happy to help!

Either use the share option from the menu in 3DE or copy and paste it 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...

Based on the error messages alone, it sounds like you’re missing the following line inside the checkForTreasure() function:

   var p2 = marker.position;

And maybe have not defined the jump() function yet, which should be above checkForTreasure() as:

 function jump() {
   if (avatar.position.y > 0) return;
   checkForTreasure();
   animateJump();
 }

Here is my link;
https://is.gd/gLmH0u

Hello,
Thank you for helping my class out. I thought I shared all of my code with you, but I guess I did not. I have looked over your suggestions and I still have a problem. I shared with you the individual section of my code and the entire code. I truly appreciate your help. We are using your book for my class, and we are struggling. We have been able to figure out Lessons 1 - 10 fine, with fixing a few spelling errors and commons. But this project we are not figuring out our problem. We have been using inspect to help with our coding errors, when I use inspect for this one I get no errors.

Thank you again
Sharon Deutscher
Sheridan High School.

The first problem the code is present:

function checkForTreasure(){
var top = treeTops[treasureTreeNumber];
var tree = top.parent;
var p1 = tree.position;
var p2 = marker.position;
var xDiff = p1.x - p2.x;
var zDiff = p1.z - p2.z;

The second problem this is what I have in my code:
function jump(){
if (avatar.position.y > 0) return;
checkForTreasure();
animateJump();
}

I will try to send you whole to you again.

The only problem that I see in the code you shared was that the avatar is not jumping. Motion looks good. Avatar animation looks good. Scoring looks good. Fruit animation looks good. If there is something that I am overlooking, let me know.

As for the jumping, you have that perfect (hence no errors) except the tween isn’t being started because the last line of animateJump() is missing. If you include the tween.start() line as shown, everything should be fine:

function animateJump(){
  var tween = new TWEEN.Tween({jump: 0});
  tween.to({jump: Math.PI}, 400);
  tween.onUpdate(animateJumpUpdate);
  tween.onComplete(animateJumpComplete);
  tween.start();
}

If you have any other problems, let me know!

-Chris

Thank you for your help. It worked. We had both the green book and the blue book. We are now just using the blue book. (second edition). It is making it so much easier.