• Create Account

Posted 07 September 2013 - 10:39 AM

You don't need to split up the paddle into multiple sections. When the ball collides with the paddle get the distance from the y position of the ball( if the position correlates to the center of the ball ) to the y position of the paddle( if the position correlates with the center of the paddle ).

YDistance = Ball.y - Paddle.Y;


From that you'll get a value ranging from half of the paddle width to negative half of the paddle width. You can go ahead and turn it into a range from [-1,1] by dividing.

YVelocity = YDistance / ( PaddleLength / 2 );

This way the y velocity will depend on where you hit the ball with the paddle( hitting it on the top will make it have a velocity of -1, hitting it with the bottom will make it have a velocity of 1, and every position and velocity in between is attainable ) OR Vice Versa on velocities depending on where you treat the origins of x and y.

Another way to make the game more interesting is to check if the paddle is moving up or down when the ball collides and add a multiplier( negative or positive depending on where the hit happens ) which makes the ball move faster.

YVelocity = YVelocity + ( YVelocity * PaddleMultiplier );
// Paddle multiplier should be positive if moving downwards, negative when moving upwards, and 0 when not moving at all.


Take a look at this example. If the ball hits the bottom of the paddle, it's velocity will equal -1 and with a multiplier of 0.5( paddle moving down ) will make it's new velocity of the ball equal -1.5. The ball is faster because you hit it while moving downwards. However, if the multiplier is -0.5( paddle is moving up ), the ball moves slower as a penalty for hitting it on the wrong side.

Should add some fun to the game and make things interesting.

Posted 07 September 2013 - 10:36 AM

You don't need to split up the paddle into multiple sections. When the ball collides with the paddle get the distance from the y position of the ball( if the position correlates to the center of the ball ) to the y position of the paddle( if the position correlates with the center of the paddle ).

YDistance = Ball.y - Paddle.Y;


From that you'll get a value ranging from half of the paddle width to negative half of the paddle width. You can go ahead and turn it into a range from [-1,1] by dividing.

YVelocity = YDistance / PaddleLength;

This way the y velocity will depend on where you hit the ball with the paddle( hitting it on the top will make it have a velocity of -1, hitting it with the bottom will make it have a velocity of 1, and every position and velocity in between is attainable ) OR Vice Versa on velocities depending on where you treat the origins of x and y.

Another way to make the game more interesting is to check if the paddle is moving up or down when the ball collides and add a multiplier( negative or positive depending on where the hit happens ) which makes the ball move faster.

YVelocity = YVelocity + ( YVelocity * PaddleMultiplier );
// Paddle multiplier should be positive if moving downwards, negative when moving upwards, and 0 when not moving at all.


Take a look at this example. If the ball hits the bottom of the paddle, it's velocity will equal -1 and with a multiplier of 0.5( paddle moving down ) will make it's new velocity of the ball equal -1.5. The ball is faster because you hit it while moving downwards. However, if the multiplier is -0.5( paddle is moving up ), the ball moves slower as a penalty for hitting it on the wrong side.

Should add some fun to the game and make things interesting.

PARTNERS