Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

breakout and collision detection

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

well I am working on collision detection between two boxes, the paddle and the ball are both squares involved in a breakout game, here is the code I have come up with, I just want to know if this is proper code for collision detection if((x+5.0f>-20.0f+i)&&(y+5.0f>-90.0f)&&(x<-20.0f+i+40.0f)&&(-90.0f<-90.0f+10.0f)) I am not sure where to put the parenthesis, please let me know if you need more information

Share this post


Link to post
Share on other sites
Advertisement
That almost looks like the basic bounding box collision, but with one important difference that need to be changed. Your code will only work if the ball is completely inside the box, because all four conditions have to be met. Touching the box at any side should be the minimum. Replace each "&&" with an "||" so that only one side of the box will need to be checked at a time.

Furthermore, as you continue working on the game, you should probably make the ball bounce back at different angles every time, depending on what part of the paddle it hits.

Share this post


Link to post
Share on other sites
-90.0f<-90.0f+10.0f you can take this out because its always true. Also note if you change && to || this part will always make your if statement true.

You might want to consider putting the code from your other post into a function, instead of hard coding it like you have it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!