Better Collision Technique

BlitzPlus Forums/BlitzPlus Programming/Better Collision Technique

Kyler(Posted 2008) [#1]
Ok, I'm making a simple arkanoid kind of game. But I'm having issues with the collision from the ball to the bricks. I can't figure out how to get the ball to bounce off the block more realisticly...The X velocity should only change when the ball either hits the top or bottom of the brick, and the Y velocity should only change when it hits the left or the right side of the brick. If anyone even understands my problem, please help me. Thanks.


Sauer(Posted 2008) [#2]
Perhaps you mean the y should change when the ball hits the top or the bottom, and the x on either side? Thats usually how these games work...


Kyler(Posted 2008) [#3]
Yes, thats what I meant. But I don't know how to do it.


Pineapple(Posted 2008) [#4]
When the object collides with a wall, negate the perpendicular velocity.


Sauer(Posted 2008) [#5]
Sorry, wrong post... my apologies


Kyler(Posted 2008) [#6]
B+man, I'm not sure you understand the question...I KNOW how to make something bounce off of a wall. But not off of a brick. If the ball hit the bottom of the brick, you wouldn't want the x and y velocity of the ball to change....just the y. And if if hit the side, only x velocity changes. Corners, both.

If no one can help me with this, can someone at least explain collision between the ball and paddle, to make it where the direction of the ball depends on where it hits on the paddle?


Sauer(Posted 2008) [#7]
Ah ok I understand your question now.

Basically you want to check if there's a collision, then check where the ball is during that collision in relation to the brick.

If IMAGESCOLLIDE(image,x,y,frame,ball,bx,by,bframe)
  If bx<=x or bx>=x+IMAGEWIDTH(image)  ;if its outside the brick's x
      speedx=speedx*-1
  Endif
  If by<=y or by>=y+IMAGEWIDTH(image)  ;if its above or under
      speedy=speedy*-1
  Endif
Endif


Thats what I would try. This is assuming that your ball is midhandled and the bricks are handled at 0,0.