# How to make Pong Ball Control?

I want to know how can I make the control of the Pong Ball in Plain Javascript. I would like to know how to make the ball faster when it hits the edges just like the original pong game, or how if the ball hit's the middle of the paddle it would go straight and slow. I just want to get a feel for how it works.

You calculate the ball's x position and the middle position of the paddle (x coordinate too of course). For the formula, you could do it like this: speed = extraSpeed * distance / (0.5f * paddleWidth) + constant;
For distance, you can do it like this: abs(paddleMiddle.x - ball.x); We don't want it to be negative/minus.
Okay, with the formula above distance / (0.5f * paddleWidth) will return 0.0f when the ball hits the middle (distance = 0.0f), and will return 1.0f when the ball hits the edge of the paddle (it can return more than 1.0f though, you might want to do something about it like clamping the value or perhaps checking the distance from the side of the ball). This value will multiply extraSpeed, so the ball will not gain any extra speed when it hits the middle and gain full extra speed when it hits the edge of the paddle. And constant here will act as the base speed or you can say the slowest speed (when it hits the middle) you don't want the ball to stop when it hit the middle, do you?