My student is building a game similar to atari breakout. But he is having issue with bounciness of the ball when it collides with the blocks. I tried multiple things to change the velocity of it or change it to sprite.x and .y but nothing seems to work. Would appreciate any help.
I don’t know whether the student has changed the code since you posted, but I see a problem in that the function (blockBreak) that checks to see whether the ball is touching the block is called after the bounceOff is used in the draw loop. That means that the ball has already bounced off the blocks when you check to see whether it is touching. Instead of doing that, take the bounceOff calls out of the draw loop itself, and inside the blockBreak function, use bounceOff inside the conditional instead of isTouching, like this:
if (breakoutBall.bounceOff(block)) {
block.scale = 0;
increaseScore();
}
bounceOff returns true or false according to whether it bounced off something, so this conditional will both bounce the ball off the block and runt he code inside the off statement if it did bounce off.
(necroposting)
bounciness is higher than 1
each time it collides the speed goes up by a factor of 5
speed = startingvalue*5^bounces
set the bounciness to 1