Sign in to follow this  
SonicD007

Pong Paddle ball collision [rect to rect]

Recommended Posts

SonicD007    464
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
ItsDan    104
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this