# [Pong Game] More relistic ball ricochet?

I am going to program a 2pl pong game, and I was wondering if there was a way to make ball ricochet a bit more realistic, because now I use a random num that I add to my Y.
(The players will be on the left and right of the window)

``````if self.vec.y < 10: #if the ball touches the top side
#this will be added to my Y until i hit something else
self.angle = randint(1,5)
if self.vec.y > height - 10: #if the ball touches the bottom side
#this will be added to my Y until i hit something else
self.angle = -randint(1,5)
``````

Or this randomness its fine because its harder to predict the ball?

1 Like

On that last question, itâ€™s completely dependent on which way you like more yourself. You can leave it random, or have some smart algorithmâ€¦

I, however, when your role is moving a paddle to not miss the ball, like when the ballâ€™s reflect angle is dependent on which part of the paddle it hit.

So, what I suggest is, on the moment of collision,

• Subtract ballâ€™s position by paddleâ€™s middle point position
• Divide the resulting number by 5 so that it wonâ€™t be too big
• Set `self.angle` to the result of that.

This makes it more similar to some breakout games, as, when you master this technique, you can get the ball to ricochet in the precise specific angle you want, raising the potential skill ceiling in your game. :v

2 Likes