How can I make the ball bounce off the edges and stop after a little bit of bouncing

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

Link to the project or level: [replace with link to the curriculum or get the “Share” link to a project]
What I expect to happen: i need to make pool ball bounces at edges and stop just like in real life.
What actually happens: It keeps moving or keep stuck at edges
What I’ve tried: I have tried counter pattern n velocity and bounciness.

link is here

Hi @sanac2086,

The game looks great to me! The balls bounce off the edge and eventually slows to a stop. Have you figured it out? If not, can you give a little more detail in what you would like to happen?

~Michelle

I wanted to move the balls so can stop in the center or somewhere else than an edge on the table like in real pool table.

Velocity is not going to get at zero for the ball unless they get to an edge.

Thanks for helping me out with this.

SC

@sanac2086,

Good morning! Looks like a fun and challenging project. Right now, you are programming it so a random velocity is assigned to each ball after the cue ball pushes at least one of the balls into an edge. That velocity will continue until the ball hits another edge. To get it to slow down and stop, you will have to probably have another command somewhere in the draw loop that affects the velocity of each ball to slow it down IF it’s not already at zero, so the pseudocode might be something like this:

If ball velocityX or ball velocityY are not zero, set ball velocity X and ball Velocity Y to 90% of their current velocity.

Of course the percentage may have to be played with and you may need to add another conditional that makes their velocity = 0 if it is so small that it shouldn’t matter … otherwise 90% of any non-zero number will still be a non-zero number.

Hopefully this makes sense. You may also encounter some small difficulties with your groupball statements because right now, if any ball hits an edge, ALL of the balls get the random velocity. This kind of works with the three balls that are all close to each other, but when they spread out and another one hits a different edge, it may cause all of them to get a new random velocity.

Good luck and check back in if we can help any further!

Mike

1 Like

Thank you so much!
I am excited to try it out!
Will definitely get back to you if I have any questions.

Thank you again.