Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is the solution to prevent the Breakout game ball to get "glued" to the "sticky" paddle for the Stanford CS106A Class
if (collider == paddle) {
/* We need to make sure that the ball only bounces off the top part of the paddle
* and also that it doesn't "stick" to it if different sides of the ball hit the paddle quickly and get the ball "stuck" on the paddle.
* I ran "println ("vx: " + vx + ", vy: " + vy + ", ballX: " + ball.getX() + ", ballY: " +ball.getY());"
* and found that the ball.getY() changes by 4 every time, instead of 1,
* so it never reaches exactly the the height at which the ball hits the paddle (paddle height + ball height),
* therefore, I estimate the point to be greater or equal to the height at which the ball hits the paddle,
* but less than the height where the ball hits the paddle minus 4.
if(ball.getY() >= getHeight() - PADDLE_Y_OFFSET - PADDLE_HEIGHT - BALL_RADIUS*2 && ball.getY() < getHeight() - PADDLE_Y_OFFSET - PADDLE_HEIGHT - BALL_RADIUS*2 + 4) {
vy = -vy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.