# Thread: 2d Collision Detection in openGL

1. ## 2d Collision Detection in openGL

As some of you may know, I'm currently undertaking a simple pong game, it will be my first game, and the road block I am at right now is making the paddles work, I can't figure out a good way to detect collision between the ball and the paddle.....

I've tried the force methods....

if blank = blank blank blank blank then make the ball go right direction, but i just cant make anything work, any suggestions anyone?

2. Here is a very easy way to get you started.

Make a bounding box around your ball. So then you have a bounding box (ball) and a bounding rectangle (paddle). You should be able to test if the ball is *about* to move inside of the paddle. Before you update the ball's position, you check the new points of your box to see if any of them will be inside the paddle, if they are then you know you have a collision. A simple way to respond to this collision detection is to reflect the velocity vector about the surface of the paddle, which is probably vertical. Then that is your new velocity vector for the ball and then update as normal.

3. Code:
```typedef struct{
int x;
int y;
int x2;
int y2;
x = starting position of paddle
y = ...
x2 = x + size of paddle image
y2 = ...

4. Lesse

Make a loop to check the XY coordinates of the translatef function, if the xy coordinates are inside ----(paddle inequality)------ then a collision has occured, and from there i invert the x speed to make it go back the opposite direction.......

5. i see a potential problem that my paddles have, they are drawn like this

Left Top Right
Left Top Right
Left Center Right
Left Bottom Right
Left Bottom Right

I need to make it so my drawing point for my paddle is at the bottom left, not the very center.....

another to the to do list