Problems with square collision
So I need to program the collision of a square. The ball that will hit the object has a velocity of 4pixels/run and doesn't disperse (after collision the velocity of the ball rotates with 90 degrees).
I make two variables called xball and yball who represent the position of the middlepoint of the ball.
First I program one of the x-sides of the square to collide if the xball+radius is greater than the xposition of this side of square. I also put the two y coordinates of the square n the IF statement and also put that the xball+radius must be smaller then xposition+5 of the side of the square (since velocity of ball is 4px/run)
Now I'd like to program the y-sides of the square as well...and now comes the problem:
If I program the y-sides of the square in the way as the x-side I just did that I will have a "Bugged zone" where the ball will reflect with 180 degrees which isn't something we want...
Image to clarify:
Any idea what other method I might use that doesn't have this problem? Or another method?
Thnx in advance,