Skip to main content
gamedev.net
🔒 Locked

Collision problem

Started by Doughboy Oct 17, 2003 at 11:08 AM 4 replies 1.1k views
Original Post
Doughboy
Doughboy
I have finally got my collision system mostly working, but I have encountered a puzzling problem that I am having trouble solving correctly. I am testing my system on a small pong game. The problem occurs when the ball gets sandwiched between the side of the screen and the paddle. This causes an almost infinite series of collisions between the ball and the paddle and the ball and the screen, which freezes up the game. While this problem is only apparent in a select case of a pong game, I can imagine situations in almost any game in which one object gets stuck between two others. How should I handle this elegantly?
dmounty
dmounty
If the collision is "perfect" and there are no other forces at work, this is exactly what would happen. The object in question would bounce indefinitely between the two surfaces. The answer is to either make the collision "loose" some energy, then the object would gradually slow down... or to introduce some sort of gravity, or air resistance to allow the ball to come to rest eventually.
Erzengeldeslichtes
Erzengeldeslichtes
Or you could "hack" it so that you can only have so many collisions before it returns.

If you want it "real world" you would have the ball lose energy in collisions, except paddles will give it back (you don''t just put your ping pong paddle in front of the ball, you smack the ball to throw it back towards the other player)
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
Doughboy
Doughboy
The other problem is that you can "push" the ball through the side of the screen with the paddle... Yeesh, what a mess.
Nathaniel Hammen
Nathaniel Hammen
Make the ball lose a some of it''s velocity perpendicular to the boundary . Make it so that the angle of reflection does not quite equal the angle of incidence. This will make the ball slide along the wall if the angle of incidence is small enough. If you have friction, it is possible to have the ball get stuck in the middle.

To solve the problem of pushing the ball through the wall, I would need to see your code.

--------------------------------------
I am the master of stories.....
If only I could just write them down...
I am the master of ideas.....If nly I could write them down... o
rixxx
rixxx
this is a real bitchy one. I''ve coded many pong-clones and variations, and bumped into this every time. one option is to check the collision one frame in advance, ie. so that you add velocity * update time to the position of the ball and the paddle each time you check for collisions.

then make a check that if the ball is out of bounds, reset the game.

btw. if you''re intrested, check out
http://richardox.cjb.net/multipong/
it''s a multiplayer pong with polygonal levels that rotate. it''s only 2-4 players, since I got bored during the project and never finished the network game.

-richardo


---------------------------
for(goodness_sake())
{
do
{
something();
} while(you_can());
}
---------------------------for(goodness_sake()){ do { something(); } while(you_can());}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.