I can't make it so when the ball touches the bucket the ball disapears

The balls fall dowm and each time you catch a ball, you get a point. CoSpaces Edu: Make AR & VR in the classroom







1 Like

Hi @AbdallaOmar!

You can refer to this post to solve your problem. Your code has the same issue as that post.

Also, you don’t need the forever block for collision function. You may as well take lines 10-23 out of the forever loop.

Hope this helps. :slight_smile:

Regards,
NixonLiStudentAccount X CoRichardLi :heart:

It still doesn’t work can you give me an idea of what the code could look like

@CoRichard_Li Can you help me because this project is going to be due

Hi @AbdallaOmar!

Since I don’t quite know how you plan your game would work, I have made an example game for you as a prototype. You can remix this CoSpace and adjust to your preference. Disabled lines 23-37 are to match your code since line 24 in your provided screenshot.

My prototype works like this:
The balls bounce around the box.
The bucket can be dragged across the box to catch balls.
Once the bucket collides with a ball (that is not the bomb), the score is added by 1 and the ball resets its position randomly on top of the box.
If the bucket collides with the bomb, the score is deducted by 5 and it resets its position too.
The score is displayed at the end of the game (after the time limit of 60 seconds).

Hope this helps your project, and my response is early enough. :slight_smile:

Regards,
NixonLiStudentAccount X CoRichardLi :heart:

Thanks you for the prototype, but I don’t understand how your code works. My game is basically than there is a random integer from 1-5. For every value a ball drops at a random position. My problem is that I can’t get it for the basketball to get out of the view of the view when is touches the bucket. If are able can you help me using my code because I’m a beginner and I kinda don’t understand your code. Thank you so much for helping me through this. here is a video of the gameplayhttps://drive.google.com/file/d/15gkNTheFqc7hWlrF39LuHhwBIoppK9uR/view?usp=sharing Again, thank you so much!

@CoRichard_Li I want to make it so when the ball touches the ground you lose a heart when you catch a ball the score increases and if you catcha bomb and the other balls fall on the floor you loose a life. Thanks you so much!!! :heart: :heart:

Hi @AbdallaOmar!

Sorry that I cannot make a sample code for you as I am busy at the moment. I read your reply and made the following remarks:

i. Random integer from one to five: you can put the box at x = 0 such that the five random positions can be of intervals of constant c, i.e. x = -2c, -c, 0, c, 2c. Then setting the code for resetting the position can simply be x = c * [randint from -2 to 2].

ii. Balls to get out of view when it touches the bucket: you can take a look at my code of the example game and follow my way of using the collision function (using self-defined functions). Follow my self-defined function (the “ResetBall” function) and match the variables, i.e. anotherItem = [the colliding item, aI in my collision function]; targetItem = [the ball you want to collide with the bucket]. The response should include setting the position desired and renewing the score.

iii. When ball touches ground lose a heart: you can place an invisible cuboid at the bottom of the box and set when the cuboid collided with another item, if it is in the list of [basketball, volleyball, football, etc.] (i.e. using the “XXX contains XXX?” block), one of the hearts should be deleted and immediately check if there are any more hearts left. If there are no hearts left, the game ends.

I may not be able to answer your questions if you still have issue, but I will try my best to respond asap.

Hope this helps. :slight_smile:

Regards,

NixonLiStudentAccount X CoRichardLi :heart: