question about collision detection

Started by
4 comments, last by Alexandre Brien 22 years, 2 months ago
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!
In Construction : http://www.gdev.org
Advertisement
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?

----------[Development Journal]
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
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
cha cha cha
thx a lot bshwagg that worked great =)
In Construction : http://www.gdev.org
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

This topic is closed to new replies.

Advertisement