Archived

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

Tazel

Collision Detection?

Recommended Posts


  
if(ballposition == rightpaddle)
{
	ballposition=ballposition-1;
}

else if(ballposition >= rightpaddle)
{
	ballposition=ballposition+1;
} 

else if(ballposition == leftpaddle)
{
	ballposition=ballposition+1;
}

else if(ballposition >= leftpaddle)
{
   
Would this work for collision detection?
tcache Contact Me
Formerly known as Wachar <- Thrander <- Tazel [edited by - Tazel on October 19, 2002 10:10:03 AM]

Share this post


Link to post
Share on other sites
Assuming the direction is right,
and that rightpaddle and leftpaddle represent the edges of the paddles...

According to me, that should work...

Share this post


Link to post
Share on other sites
Man I hate collision detection I''ve been working on a break out pong type game for almost a month now. I''ve implemented the collision detection for the bricks since the very first week. And 4 weeks later it still is buggy.

I think I will finish the game, and the collision detection will still not be working. ARG it makes me so mad, I''m at almost 100 lines of code I think.

I wish I could snap my fingures and it would work.

Share this post


Link to post
Share on other sites
Actually, once ballposition == paddleposition, it is too late, they are now occupying the same space. What you want to do is calculate the ball''s next position, see if that is == paddleposition and if it is, then recalculate ballposition to bounce it off the paddle.

Share this post


Link to post
Share on other sites
Doesn''t the screen''s layout go from 0 on the left to whatever the screen resolution is on the right? So the +1 and -1 should work. And also, how would I check before hand?


tcache
Contact Me


Formerly known as Wachar <- Thrander <- Tazel

Share this post


Link to post
Share on other sites
hi you can check the ball''s next position by doing this:

ballNextPos = ballCurPos + (ballVel * dt);

then, if(ballNextPos >= rightpaddle)
...

don''t use equal especialy if your using float, it would rarely reached the equal comparison,



Share this post


Link to post
Share on other sites