Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was just wondering about the horizontal movement of a pong ball? What is the general algorithm used with this? The ball in my pong game just move vertically and I don't know about the algorithms used for for horizontal movement. Thanks in advanced!

share|improve this question
up vote 3 down vote accepted

You have two speeds here: - ball speed (x,y) - paddle speed (x)

Ball speed is constant (positive or negative) by Y axis while speed on X axis is set depending how fast is the paddle while you hit the ball.

Simple calculation could be:

// this is called when ball hits the paddle   
function OnCollision()
    BallSpeed.x = PaddleSpeed.x * 0.5f; // 0.5f = custom factor

// you calculate new ball position here every frame
function OnUpdate(float dt)
    BallPosition.x += BallSpeed.x * dt;
    BallPosition.y += BallSpeed.y * dt;

Of course, you could also calculate X speed depending which part of the paddle it hit (if it was far edge, X speed is bigger). Usually both parameters are applied in pong games. Let me know how it went.

share|improve this answer
Worked great. Although from what I see there is no real reason to make the ball go as fast as the paddle, but with little adjustments I was able to make it tuned for my preference. Anyways thanks again! – LiquidFeline Apr 15 '13 at 10:33
I'm glad it worked. Yes, that's why I added that 0.5 factor so it's not as fast / slow as the paddle. Good luck with the project! – Blodyavenger Apr 15 '13 at 10:39
bear in mind that in the actual game, distance from the center of the paddle also affects ball speed. – Benjamin Danger Johnson Apr 16 '13 at 0:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.