   ball collision
  Hello everyone,I've been working on a breakout clone, and i'm trying to implement the ball collision with the blocks.Here my code:   public void CheckBlockCollision()   {  foreach (Block b in Level.GameObjects)  { if (b.Active) {if (this.Top <= b.Y + 16){    this._ballSpeedY *= -1;}if (this.Bottom >= b.Y){    this._ballSpeedY *= -1;}if (this.Right >= b.X){    this._ballSpeedX *= -1;}if (this.Left <= b.X + 48){    this._ballSpeedX *= -1;} }  }   }it just checks for collision in top, bottom, left, right but its not working well, my ball just moves up and down(and trembling), have no idea whats going on. Maybe a more advance collision detection with angle checking and such? but how's that done? i've no clue...Thanks in advance   
Here is another thread on this topic that might have some relevant info.   ;  Well it's trmbling cause it over step the boundry and can never escape, because you reverse the direction every step. What needs to be done is to move the ball right before the collsions. OR you need to make sure you are constant with your velocity reflection. Now this is C# right, cause i do not know how to take the floating point absolute value of a number, i guess the function is "fabs" else replecae "fabs" with the correct one   public void CheckBlockCollision()   {  foreach (Block b in Level.GameObjects)  { if (b.Active) {if (this.Top < b.Y + 16){    this._ballSpeedY *= -1;this.Top = b.Y + 16}if (this.Bottom > b.Y){    this._ballSpeedY *= -1;this.Bottom = b.Y;}if (this.Right > b.X){    this._ballSpeedX *= -1;this.Right = b.X;}if (this.Left < b.X + 48){    this._ballSpeedX *= -1;this.Left = b.X + 48;} }  }   }**************** OR ****************   public void CheckBlockCollision()   {  foreach (Block b in Level.GameObjects)  { if (b.Active) {if (this.Top <= b.Y + 16){    this._ballSpeedY = -fabs(this._ballSpeedY);}if (this.Bottom >= b.Y){    this._ballSpeedY = fabs(this._ballSpeedY);}if (this.Right >= b.X){    this._ballSpeedX = -fabs(this._ballSpeedY);}if (this.Left <= b.X + 48){    this._ballSpeedX = fabs(this._ballSpeedY);} }  }   };  I'll just assume this is 2D, but my solution can easyly be applied to 3D.for the ball I used four points of contact to check how it hit an object if it did hit an object.so lets assume the ball is 32x32 pixels in size. each point would be half way inbetween each corner. Top    x+16, yLeft   x,    y+16Bottom x+16, y+32Right  x+32, y+16now every block you check, check to see if any of these points are in that blocks bounding area, and depending on wich point, is in the block you'll know where it hit. though be careful as this isn't perfect as I found when the ball gets moving pretty fast it's possible to get stuck inside a block.   ;  ...[Edited by - BrasiLokau on June 4, 2006 12:51:23 AM];  Im not supprised that your ball is moving up and down(and trembling).Unless I missed out on something here you have to use the AND operator.Your ball should only flip direction when all the if tests is true.example:public void CheckBlockCollision()   {  foreach (Block b in Level.GameObjects)  { if (b.Active) {if (this.Top <= b.Y + 16 && this.Bottom >= b.Y && this.Right >= b.X && this.Left <= b.X + 48){    // The ball overlaps block b...}...;  none of them seem to work o.Ocan anyone give me a more detailed explanation :([Edited by - BrasiLokau on June 4, 2006 8:04:11 PM]