Skip to main content
gamedev.net
🔒 Locked

Pong collision problems...

Started by BSXrider 8 replies 350+ views
Original Post
BSXrider
BSXrider
Wow, what an original post eh? I did searrch for this but there were SO many pong posts and they all just seemed to say "how can I make pong?" Well I''m not quite that useless. I''ve made pong, and it works fine, to a point. [:D] That point is if the ball is going too fast it tends to just jump through the paddle. Sometimes it gets stuck in the paddle which is equally annoying. I can think of ways around this but none are nice solutions - what do you suggest? - seb
giant
giant
Hi.
I am guessing that the reason that the ball jumps right through the paddle or into the paddle, is because when it accelerates it moves greater that 1 unit in the direction that it travels.
I suffered from the same problem when I was writing pong, and I found a few ways around it. Here is the option I went for. It is a cheat, and may be undesirable but it works, and I was writing pong to learn DirectX, not games programiing, so I did''nt mind.

1) After each move, check to see if the x distance to the paddle is less than the acceleration of the ball. If it is, the ball may jump into or over the paddle the next move. Now check to see it the paddle is in the correct place to deflect the ball. If it is, bounce the ball now. It will be slightly inaccurate, but the game will be playing at such a speed that no-one will know.

Giant

"Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein
CaptainJester
CaptainJester
To take giant''s idea one step further, you could on the next turn, not add the velocity of the ball, but add the distance from the ball to the paddle. This way the ball will still touch the paddle, then invert the velocity as normal.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
giant
giant
I agree with CaptainJester. That is a much better idea, that what I had originally proposed. You can still use your collision detection algorithm that you already have, and a simple if statement inserted in the moveball function will do the trick.

Giant

"Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein
BSXrider
BSXrider
Cheers guys, sort-of what I was thinking - just makes more sense now you''ve written it down for me :D

- seb
Lalle
Lalle
What I did was that when I moved the ball, I calculated each step from the start position of the "jump" to the last position. That way I could check for a collition even at great speeds.

Hope it helps
Lalle
Argus
Argus
I did pretty much the same as lalle.

When the ball passes the line which the paddle can move through, I check to see where the ball wa when it hit the paddle line. Then I check to see whether the paddle was in the way - if it was then I draw it once on the paddle and then bounce it. Works fairly well.
BSXrider
BSXrider
It''s not quite as simple for me, because I''ve added a slight play on the original game in that the player can move their paddles back and forth. Like coming "in to the net" in a game of tennis.

- seb
GBGames
GBGames
Cool, reminds me of Atari Olympics. You could jump up and basically bounce the ball over from higher up. B-)

-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel

Topic Locked

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

Sign in to reply to this topic.