Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question already has an answer here:

Im currently creating a breakout clone for my first ever C# / XNA game. Currently Ive had little trouble creating the paddle object, ball object, and all the bricks. The issue im currently having is getting the ball to bounce off of the paddle and bricks correctly based off of where the ball touches the object. This is my forumala thus far:

if (paddleLocation.Intersects(ballLocation))
{
    position.Y = paddleLocation.Y - texture.Height;
    motion.Y *= -1;

    // determine X
    motion.X = 1 - 2 * (ballLocation.X - paddleLocation.X) / (paddleLocation.Width / 2);
}

The problem is, the ball goes the opposite direction then its supposed to. When the ball hits the left side of the paddle, instead of bouncing back to the left, it bounces right, and vise versa. Does anyone know what the math equation is to fix this?

share|improve this question

marked as duplicate by Byte56 Feb 12 at 15:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer 1

change

ballLocation.X - paddleLocation.X

to

paddleLocation.X - ballLocation.X
share|improve this answer
add comment

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