colliding with paddle

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

colliding with paddle

dmoeller
I am making a breakout game. When I set my code to have the ball collide with the paddle, it always bounces off where the paddle is vertically, all across the screen. It only looks at the y value, not the x value but I have tried nested if for the x value and a & for the x value in my if statement. Here is my code so far.

                //if the ball collides with the paddle
                if ((ball.getY()+ball.getRad()) > paddle.getY())
                {
                        if ((ball.getX()-ball.getRad()) > paddle.getX())
                        {
                                let vert = false;
                        }
                }
                return;

Please let me know what I am doing wrong. Thank you.


P.S. vert=false means the ball goes up
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: colliding with paddle

cadet1620
Administrator
The inner if is the problem.  It is only testing for one side of the paddle.

You want to test if the ball is left of the right end of the paddle and is right of the left end of the paddle.

--Mark
Loading...