#### Archived

This topic is now archived and is closed to further replies.

This topic is 6092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey Im currently making my very first game (a pong game =\ ) and I have come to the point where I need to use collision detection (unless theres some other way I dont know of??). Anyway I was wondering what would be an EASY way of knowing when my ball (GL_POINTS) and my bar (GL_LINES) collides so I can change the direction of the ball. Any help is appreciated thx!

##### Share on other sites
How about loop through all of the possible points of collision on the line and see if your ball (x,y) position is equal to the point?

##### Share on other sites
check if the height, y-value of the ball falls within the range of the paddle...
{
//collision!
ball.xSpeed = -ball.xSpeed; //reverse the balls direction
}
else
{//player loses
}

something like that if thats how your implementing the pong
good luck..
schwags

##### Share on other sites
check if the height, y-value of the ball falls within the range of the paddle...
{
//collision!
ball.xSpeed = -ball.xSpeed; //reverse the balls direction
}
else
{//player loses
}

something like that if thats how your implementing the pong
good luck..
schwags

##### Share on other sites
thx a lot bshwagg that worked great =)

##### Share on other sites
in my pong game i use:
if (test.y1 >= player1.y1 &&  test.height <= player1.y2 && (test.x1 + test.width )== player1.x){player1.collide++;}

but for somereason the collide counter increases when ball passes above the paddle. it works fine except that, i cant figure out why though maybe someone could help me

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009802
• ### Who's Online (See full list)

There are no registered users currently online

×