I hope you can understand my question! I'll try to be very clear.
As you can see, if the ball hits more towards the bottom or top of the paddle, the angle in which it bounces gets larger, and if it hits closer to the middle, the angle becomes narrower.
Here is the algorithm and it works (Check code comments):
player_interesected_ball = detect_collision(ball, player) #It's a function that just detects if two rectangles collided if player_interesected_ball : offset = (ball.y + ball.s - player.y) / \ (player.height + ball.s) # ball.s is the ball size like 10px it means that is 10px wide and 10px high phi = 0.25 * math.pi * (2 * offset - 1) ball.vel_x *= -1 ball.vel_y = ball.speed * math.sin(phi)
This code works when the paddle is placed on the Right or Left side of the screen but I want to know what should I change in these values to make it work when the paddle is placed on the bottom of the screen.