I’m doing a code where i want a ball(pong) to bounce off a rectangle(bouncer). does anyone know the code for a bounce off?
First, you’ll need to determine if the paddle and the ball have collided. Look at this image:
The circle is the ball. The red rectangle is the paddle. Their centers are marked. How can you tell that they have collided? Note that you know where they are and also how big they are (you need to know these things to draw them!).
Once you have determined that a collision has occurred, you will want to change the direction the ball is going. A simple way to do this is to negate it’s X or Y speed.
2 Likes