🔒 Locked
Pong collision problems...
Advertisement
Original Post
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
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
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
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
---
Make it work.
Make it fast.
"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
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
Giant
"Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." --Albert Einstein
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.
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement