So I am making a breakout game in android studio.
And after making a game loop and basic collisions with the paddle and bricks I've noticed that my ball has started to clip through my bricks and paddle after increasing the speed of it.
The problem lies that it collides two times in a frame, so my basic collision is not enough for it.
I've read about using vector math for a solution. But it's too much for me too wrap my head around it.
I'm referring to answer of this question:
Refer Here
if (RectF.intersects(bricks[i].getRect(), ball.getRect())) {
Brick brick = bricks[i];
if(ball.getRect().centerX()>brick.minX() && ball.getRect().centerX() < brick.maxX()){
ball.reverseYVelocity();
if(ball.getRect().top > brick.getRect().centerY()){
ball.clearObstacleY(brick.getRect().bottom - ball.getRect().height());
} else {
ball.clearObstacleY(brick.getRect().top + ball.getRect().height());
}
} else {
ball.reverseXVelocity();
if(ball.getRect().left > brick.getRect().centerX()){
ball.clearObstacleX(brick.getRect().right + ball.getRect().width());
} else {
ball.clearObstacleX(brick.getRect().left - ball.getRect().width());
}
}
And my ball update is:
public void update(long fps, float speed){
rect.left = rect.left + (xVelocity*speed / fps);
rect.top = rect.top + (yVelocity*speed / fps);
rect.right = rect.left + ballWidth;
rect.bottom = rect.top - ballHeight;
}
So how would I transform this into something like this:
Demo
Thanks in advance!