# How to reflect a Ball hitting paddle/wall

Hello,

I have made a Pong game.

I have position of the ball, and its velocity x and y.

Ive searched alot but i just cant get the thing working. I have a paddle where i want the middle to reflect the ball horizontaly and when the ball starts getting closer to the edges i want the ball to bounce sharper. Ive tried using radians, but i just cant get the things working.

Do some of you guys have any good tutorial on this for Monogame/XNA or any good tips?

try someting like this

vel.X = MathHelper.Sin(px);
vel.Y = MathHelper.Cos(px);

minangle and maxangle are angle to return ball at,
paddlecontact is value from 0 to 1 depending on point on collision along x axis

EDIT: could have got sin and cos wrong way round. Can never remember which way it goes.

It depends on the effects you’re going for. A general simple one would be to reverse the velocity depending on where hit. So with a starting velocity of X, Y, if it hits the top or bottom of the screen you would make the new velocity X, -1 * Y, if it hits the left or right side of the screen it would become -1 * X, Y. This disregards physical effects like friction or I believe it’s called absorption, but should work for you.

When it hits the paddle you will probably want to add the velocity of the paddle (or some fraction of it) to the ball, so if the ball is moving in a positive direction and the paddle is moving in a positive direction you would get a Y velocity of Ball Y + Paddle Y and X velocity of -1 * X. If the ball is going in a negative direction and the paddle is going in a negative direction, similar would be applied… and if the ball and the paddle are going opposite directions on the Y it would be possible to negate or even reverse the ball’s Y velocity.

Now if you wanted to apply real physics to it that is far beyond my knowledge as you would have ball rotation and things like that… but the above should at least get you started until you’re ready to look into the real physics of it.

I made it work using lerp function
Thanks for great replies. Got handy aswell!