• entries
55
55
• views
24503

# Birds Flew Backwards

107 views

So I haven't managed to finish Two Player Pong today but I did manage to get scores working, a regulated frame rate and producing a new ball when the old one goes out of play (now that I've listed what I've done it doesn't sound like a lot [lol]).

Unfortunately, I have a bug which occurs when one of the paddles 'lands' on the ball, if you see what I mean. I think its got something to do with me not reversing the y velocity but I don't know where to put it.Can anybody help? I'll also have a think for myself at work. Here's the code:

// Check if the ball hits player oneif (ball_top < player_one_bottom && 	ball_bottom > player_one_top &&	ball_right > player_one_left &&	ball_left < player_one_right){	// Reverse the x velocity	ball->ReverseVelX();}// Check if the ball hit player twoif (ball_top < player_two_bottom && 	ball_bottom > player_two_top &&	ball_right > player_two_left &&	ball_left < player_two_right){	// Reverse the x velocity	ball->ReverseVelX();}

Anyway, I have a few days off work from tomorrow which should give me plenty of time to finish Two Player Pong and get started on my Breakout clone.

-AEdmonds

Is it possible that after you reverse the velocity, the ball is still "inside" the bat, so next frame it gets its X velocity reversed again, and so on and so on?

If player 1 is always on the left and player 2 on the right, I'd try setting the ball X velocity to +1 for player 1 collisions and -1 for player 2 collisions explicitly.

The alternative is, when you get a ball collision, to move the ball out of the bat at the point you detect the collision (e.g. for player 1, set ball_left to equal player_right+1 or whatever).

HTH

Yes I found that (after changing its colour) the ball seemed to be bouncing inside the paddle. Thanks for the suggestions, I will try them out tomorrow.