   block breaker collisions
  Does anyone know some good code or a link to a tutorial on realistic collisions between the ball and the blocks in a block breaker style game? I am writing this game in BlitzPlus, although I will probably be able to decipher the collision algo or whatever from another language.Thanks.   
  Go to the Game Engine Forum and there's a link to a site with a list of engnes and physics engines, some of the physics engines you can jus plug in.   ;  I dont really want to use an engine, I was hoping for the theory behind the collisions or a little bit of source.   ;  If the displacement per frame of the ball is not too great, here is a simple method that works well:- Find the closest point on the block to the ball (circle) center- Find the length of the vector between these points- If it's greater than the ball radius, no collision- Else the collision normal is this vector, normalized- Move the ball along the normal by the radius minus the original length of the difference vector- Reflect the ball's velocity about the normalI may have missed some details or gotten something wrong, but that's the basic idea (please ask if any of it needs clarification). Also, as with most collision detection methods, some tweaks/tolerances/epsilons may need to be added to prevent errant behavior such as the ball getting stuck.   ;  Is this 2D or 3D?in either case, you can separate the block/cube into lines/planes.Then take the center of the circle/sphere and plug it into each of the lines n and if the absolute value of the result is smaller than the radius, there is a collsion. Aslo watch out because lines are infinite, so you'd have to make there's limitations, if you want, i can give you some code?   ;Quote:Original post by TheC00L1Is this 2D or 3D?in either case, you can separate the block/cube into lines/planes.Then take the center of the circle/sphere and plug it into each of the lines n and if the absolute value of the result is smaller than the radius, there is a collsion. Aslo watch out because lines are infinite, so you'd have to make there's limitations...Just using hyperplanes won't handle convex corners correctly. As you noted you have to make adjustments for this, which is what the method I posted above does. (Also note that the ball vs. box method will work as-is in either 2D or 3D.)   ;  Yeah, some of what i post is similar to yours, but the convex edges problem can be fixed by solving for an y or a x and test is it is bigger than thw width and height of the box. But in actuallity, it is finding the nearest point like you said.   ;Quote:Original post by jykIf the displacement per frame of the ball is not too great, here is a simple method that works well:- Find the closest point on the block to the ball (circle) center- Find the length of the vector between these points- If it's greater than the ball radius, no collision- Else the collision normal is this vector, normalized- Move the ball along the normal by the radius minus the original length of the difference vector- Reflect the ball's velocity about the normalI may have missed some details or gotten something wrong, but that's the basic idea (please ask if any of it needs clarification). Also, as with most collision detection methods, some tweaks/tolerances/epsilons may need to be added to prevent errant behavior such as the ball getting stuck.   public void CheckBlockCollision()   {  foreach (Block b in Level.GameObjects)  { if (b.Active) {int x1 = this.Center.X;int x2 = b.Center.X;int y1 = this.Center.Y;int y2 = b.Center.Y;int d = ((x1 - x2)^2 + (y1 - y2)^2)^1/2;if (d < 5){    return;}else{    // collide} }  }   }well i've tryed a couple of things, but nothing seem to work.can you give-me a example? in any language would be great... thanks[Edited by - BrasiLokau on June 4, 2006 9:33:41 PM];Quote:Original post by BrasiLokau   public void CheckBlockCollision()   {  foreach (Block b in Level.GameObjects)  { if (b.Active) {int x1 = this.Center.X;int x2 = b.Center.X;int y1 = this.Center.Y;int y2 = b.Center.Y;int d = ((x1 - x2)^2 + (y1 - y2)^2)^1/2;if (d < 5){    return;}else{    // collide} }  }   }well i've tryed a couple of things, but nothing seem to work.can you give-me a example? in any language would be great... thanksThat's a circle-circle test. I'll try to post some code tomorrow if I have time, but meanwhile, googling 'closest point AABB' might turn up an example of how to find the closest point on each block to the ball center (which is what the algorithm I described earlier requires).   ;  Theres a another way, by increasing the power, you make a circle more square, but i don't re,meber the different properties, well i'll give you an example. float d = ((x1 - x2)^100 + (y1 - y2)^100)^1/100;This should work, to a certain extent, hopefully it won't overflow.   