# Thread: Problems with square collision

1. Member Join Date
Jul 2011
Posts
53
Rep Power
0

## 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?

Reskaillev  Reply With Quote

2. ## 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...
Are you sure? Double reflection from top and side or side and top would be 180 degs

I need to program the collision of a square
What is the square colliding with?  Reply With Quote

3. Member Join Date
Jul 2011
Posts
53
Rep Power
0

##  Originally Posted by Norm Are you sure? Double reflection from top and side or side and top would be 180 degs

If the ball hits the square in its corner --> it should reflect 180 degrees indeed. Problem is that if the ball is in the bugged zone, like the ball comes
from the left and hits the yellow zone (On the X-side) the program will reflect the ball with 180 degrees and not with 90 degrees like a normal collision woul do. (velocity x AND velocity Y get reversed, while only velocity X needed to be reversed)

What is the square colliding with?

The square is colliding with a ball, a circle with radius 10 and middlepoint described by xball and yball
The ball hits the square and is supposed to be reflected properly, the square doesn't move at all.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•