Collision Detection?

Started by
4 comments, last by Tazel 21 years, 6 months ago

  
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]
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Advertisement
Assuming the direction is right,
and that rightpaddle and leftpaddle represent the edges of the paddles...

According to me, that should work...
_________________________________________"You're just jelous because the voices only talk to me"
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.
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.
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
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
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,



http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,

This topic is closed to new replies.

Advertisement