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...

Any idea what other method I might use that doesn't have this problem? Or another method?

Thnx in advance,

Reskaillev

07-31-2011, 11:26 PM

Norm

Quote:

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

Quote:

I need to program the collision of a square

What is the square colliding with?

08-01-2011, 09:38 AM

Reskaillev

Quote:

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.