![]() |
OO Game Programming tutorial - Part 9 |
Ball/Wall collisionsTesting for this type of collision is exactly the same as we did for the paddles. The only difference is when the collision occurs we want the ball to bounce off and go the other direction. To make the ball go in the opposite direction the y vector component is just inverted. Therefore if we are travelling towards the top wall yi is positive, to go down we make it negative. The bottom wall is the same. ball.yi = -ball.yi This line acheives it for both scenarios. Check out that collision test doing it's wonders:
|