I need help - if you try hitting the ball with the sides of the paddle, it gets stuck inside the paddle and bounces around a bunch of times. How can I fix this so that it just bounces off of the side?
Arrow keys for bottom player, ESDF for top player.
I have never been that good at these type of collisions so there is probably a better solution.
I was initially getting:
It kept picking up speed in this scenario so I thought the speed was the trigger.
I edited the code like so
-----lower pad collision with ball----- if (ball.pos.y + ball.size >= pad1.pos.y-ball.size+1) and ball.pos.y + ball.size <= pad1.pos.y+ball.size and (ball.pos.x - ball.size + ball.spd.x >= pad1.pos.x-4 and ball.pos.x + ball.spd.x <= pad1.pos.x + pad1.w + ball.size + 2)
notice the + ball.spd.x on both calculations against the ball.pos.x
now it does this:
Like I said there is probably a much better way of calculating this but hopefully it's a start!
good luck and happy coding
[Please log in to post a comment]