My pong game problem - hit detection

Started by
13 comments, last by Zahlman 15 years, 3 months ago
Though it doesn't work so well for the BluePaddle it messes up everything if I make a detection for the bluepaddle as well

it doesnt make any sense instead of bouncing of the left side it bounces on the right side, thus making it bounce and forth against right paddle and the right wall.

[Edited by - Roberts91 on December 27, 2008 8:43:51 PM]
Advertisement
The Blue paddle is on the right side of the screen, right? Did you make sure to check if the pong ball's x position is greater than (rather than less than) the blue paddle's x position?
Yes I did change the sign. In fact I tried diffrent combos of sign changing I was am that stumped.

Nevermind I got it fixed thanks again. (I thought I had tried that)

Well what I did was change the sign and negated the velocity instead of +'ing it like you have to do on the left hand paddle(red).
Is it a copy and paste error, maybe? Did you make sure to use the BluePaddle object instead of the RedPaddle?

If so, could you post that snippet for me?
Quote:Original post by Roberts91
Well what I did was change the sign and negated the velocity instead of +'ing it like you have to do on the left hand paddle(red).


No no no no no no no no no.

Look. If the ball is moving to the left, its x-velocity is negative, yes? Let's say its x-velocity in that case is V (I don't care what the actual value is). If the ball bounces, it should start moving just as fast to the right. "To the right" is the opposite direction as "to the left", yes. Now, what velocity has the same magnitude as V, but in the opposite direction? -V, of course.

Now, if the ball is moving to the right, its velocity is positive. Let's say that its velocity in that case is V... look, whether V is positive or negative doesn't matter. What you want to do is replace the current x-velocity with the negative of that x-velocity, in either case.

Now, how might you handle reflections off the top and bottom of the screen? :)

This topic is closed to new replies.

Advertisement