Archived

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

Alexandre Brien

question about collision detection

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 this post


Link to post
Share on other sites
Guest Anonymous Poster
check if the height, y-value of the ball falls within the range of the paddle...
ie: if((ball.y < paddle.yMax && ball.y > paddle.yMin))
{
//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 this post


Link to post
Share on other sites
check if the height, y-value of the ball falls within the range of the paddle...
ie: if((ball.y < paddle.yMax && ball.y > paddle.yMin))
{
//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 this post


Link to post
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

Share this post


Link to post
Share on other sites