[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.
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!