Breakout... Getting the ball reflection X angle when htitting paddle / bricks

Posted by Steven Wilson on Game Development See other posts from Game Development or by Steven Wilson
Published on 2012-08-28T22:29:58Z Indexed on 2012/08/29 3:50 UTC
Read the original article Hit count: 293

Filed under:
|
|
|

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?

© Game Development or respective owner

Related posts about XNA

Related posts about c#