Jump to content
  • Advertisement
Sign in to follow this  
SonicD007

Pong Paddle ball collision [rect to rect]

This topic is 4098 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

I've looked on google to see how to get the collision test for the paddle and ball, but I couldn't find anything that helped me, and I tried to think what exactly I have to test but whenever I tried to test that the ball just went right through the paddle =( Can someone tell me what x,y,w,h values i would be testing? its a rect to rect test, C++ language SDL api. I got the ball to bounce off teh walls and to reset and register as a point if it hits the side, but I can't get the collision for the ball and rect to work. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
My simple check involves seeing if:

box1's X is > box2's x+width
box1's x+width < box2's X


Repeated for as many axes as you need. In this case I'm not really checking for collision, I'm checking for a non-collision (ie, if either of those statements above is true, the boxes can't be colliding). If none of the conditions are true, then boxes are colliding.

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!