Jump to content
  • Advertisement


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


The paddle and ball seem to get stuck but I dont know why...

This topic is 5526 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 made this pong game which I intend to expand upon; however, sometimes when the ball and the paddle collide the do not unstick can you take a look and tell me what you think? the game was written in C++ and used the techniques from SAMS 24hr Game Programming. Contact me via ICQ to get the file

Share this post

Link to post
Share on other sites
I'm not genius or a mind reader...but it sounds like the problem lies somewhere in your algorithm...take this into consideration...

bool Ball_Paddle_Collision(); // returns TRUE if there is a collision

if (!Ball_Paddle_Collision())
// if there is no collision, move the ball


If the position ball accidentally gets shifted into the location of the paddle and causes a collision, the ball will no longer move and will stay in the same location....right where it collided.

don't know if that helps at all...overlook your math where the ball is very close to the paddle and make sure this isn't happening.

[edited by - Malikive on August 8, 2003 3:23:51 PM]

[edited by - Malikive on August 8, 2003 3:24:22 PM]

Share this post

Link to post
Share on other sites
I had this problem in my first game (pong). It was caused because I detected a collision between the ball and the paddle and then simply reversed the direction of the ball along whatever axis... usually x. So it looked like this, in pseudocode:

if (Collision())
Ball.x = -Ball.x;

Now, stop and think about what happens if the ball went into the paddle because it updates every frame and you have no code to make it stop when it hits the paddle (it just reverses without making sure the ball isn''t inside the paddle). If the ball isn''t moving fast enough to escape the paddle before the next frame, it will once again register as a collion and the direction of the ball will be reversed -- right back to the way it was in the beginning. And if it couldn''t escape the first time, it won''t escape the second time either... it''ll just bounce back and forth frame by frame, never going anywhere, appearing to be stuck to the paddle Hope that helps.


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor


Share this post

Link to post
Share on other sites
one option I find helpful is to check if the place I WANT TO MOVE will cause a collision BEFORE I move. By doing this you avoid making the initial collision where you would get stuck but to the user it looks like they collided and moved on.

Share this post

Link to post
Share on other sites

  • 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!