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

Started by
2 comments, last by JerkyRobot 20 years, 8 months ago
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
The great thing about games in history, is just that, they are history and its time for better games!
Advertisement
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 collisionif (!Ball_Paddle_Collision()){     Move_Ball();     // 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]
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

Yanroy@usa.com

--------------------

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

Yanroy@usa.com

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.
Evillive2

This topic is closed to new replies.

Advertisement