# Breakout angle calculation

I am making my first game in python and I am really stuck at with a physics problem. The game I am trying to make is a copy of the game Breakout. In Breakout, the player controls a "paddle" at the bottom of the screen, which the ball will bounce off of.

I have got the collision to work, but I want the angle between the ball's direction vector and the "paddle" to have an impact on the angle at which the ball leaves the paddle. How can I make this work? I have tried a lot of things, but I can't get it to work.

In these situations I want the angle to be sharper when the ball hit's closer to the edge of the paddle. How can I calculate and make these angles to work?

If you think in terms of the horizontal and vertical velocities of the ball then this may make the problem more tractable.

So I assume that when a collision is detected that this is handled by adjusting the vertical velocity. The most trivial way to do this would be to invert it so that the ball will start travelling up instead of down. You could for example do this by multiplying the y-velocity by -1. So this gives you the basic bounce, but you want it to bounce differently based on where it hits the paddle so you want to change the x and you velocity by different amounts depending on where the paddle collides with the ball. In the case you describe for example - assuming that you don't want to alter the speed that the ball is travelling you will need to create a function that uses pythagorus's formula to proportionately split the x and y velocities to a new ratio as a function of where it colliding with the bat.

In your example it looks like you want to transfer more of the y velocity to x velocity in your right-hand picture. In your left hand picture it looks like you want to invert the x velocity as well as the y velocity but also redistribute the combined x+y velocity so that more is transferred to the inverted x than the inverted y.

Perhaps a few more examples to demonstrate the desired behaviour across the bat and we could explore some functions?

• Thanks. When the ball come from the left to hit the paddle on it's right side, both the y- and x-velocity are reversed so that the ball will travel in the direction it came from. – JoakimSjo Jan 29 '17 at 8:19 r = d - 2 (d * n) n


where d * n is the dot product, and n must be normalized.

In your case n is looking up. To change the angle near the edges, make n tilt to the side near the edge.