I was trying to add some breakable and unbreakable block on my simple breakout game. But everytime the ball hit the gap between two blocks the ball just pass through it.
I dont know if the collision between the ball and the block is the problem cause the code is just for checking the Box - Circle collision
private bool circleCollision(Ball ball, Blocks block)
{
Vector2 center = ball.getRadius();
Vector2 AABB_Half_Extents = new Vector2(block.Width / 2,block.Height / 2);
Vector2 aabb_center = new Vector2(block.Position.X + AABB_Half_Extents.X,
block.Position.Y + AABB_Half_Extents.Y);
Vector2 difference = center - aabb_center;
Vector2 clamped = Vector2.Clamp(difference,-AABB_Half_Extents,AABB_Half_Extents);
Vector2 closest = aabb_center + clamped;
difference = closest - center;
if(difference.Length() < ball.BallRadius)
{
return true;
}
return false;
}
Does anyone have any idea why is it passing through the gap of the the blocks? Its suppose the ball back.