I am trying to make a ball bounce off the edges of a rectangular shaped paddle, what I have done so far, is making the ball bounce off the top edge of the paddle. But whenever the ball touches any other side (right or left), it gets stuck within the paddle, and won't bounce off.
In order to make the ball bounce off the top of the paddle I have used the below straight forward code:
// bounce ball off paddle
if (object == paddle)
{
velocityY = -velocityY;
}
Can anyone help me enhance this code, so that it can detect, whether the ball has touched the right or left side of the paddle, and make it bounce away.
Please note, that I am using C.
Thank you,