Okay, so my paddle collision is working fine:
if(velo.y > 0){
float t = ((position.y - radius) - paddle.position.y)/ velo.y;
float ballHitX = position.x + velo.x * t;
if(t <= 1.0){
if(ballHitX >= paddle.position.x && ballHitX <= paddle.position.x + paddle.width){
velo.y = -velo.y;
}
}
}
But my wall collision isn’t. (the ball goes up when under the paddle, and down when not)
if(velo.y < 0){
float t = ((position.y - radius) - (wall[2].y + wall[2].height))/ velo.y;
if(t <= 1.0){
velo.y = -velo.y;
}
}
How do I stop this error and make it so the ball bounces off the wall?
My guess is that you’re flipping it twice.
So, when you do your paddle, it goes like this:
But when you do your wall, it goes like this:
So because yu’re hitting both conditions, it flips twice.
You need to determine whether or not you’ve flipped already to prevent double flippage.