2
votes

I am making a 2D Brick Breaker game in Unity.

I have an issue with the scenario when ball hits in between two bricks. I have BoxCollider2D attached to all bricks and a CircleCollider2D attached to the ball. When the ball hits between 2 adjacent bricks, it bounces back in the same direction as if it hit the edge of the brick. There is no edge in between, but two adjacent bricks form a continuous surface. So, the ball should bounce off of the surface (in other direction) instead of bouncing back.

enter image description here

Anyone knows of any solution to tackle this problem? I asked this in the Unity Physics forums but didn't get any answer, so checking if anywhere here might have had this issue.

Thanks, Mukul

2
You might use one box geometry but different textures to mock it as two blocks.David
Cant do that. I am detecting collisions individually for each block, based on its box geometry.mukul
can you merge aligned box colliders at runtime?nyro_0
Like i said, i am detecting ball collisions for every brick based on its collider. So merging box colliders wont help, as it will make the collision detection useless.mukul

2 Answers

0
votes

I am guessing this could be the problem:

When your ball is hitting the bricks with a strong force, There is a chance it might move one of the bricks by a very very slight distance, even if the mass of the brick is much heavier.

This movement might cause an uneven surface, which is why the ball bounces back in the same direction.

Try adding a Rigidbody Component on every brick (if you have not done it already), and set its isKinematic property to true.

Let me know if this solves it.

0
votes

Way 1:

Use one box collider for the wall, but not for every single brick. This will fix your issue + will optimize your project.

Way 2:

You need to build wall programmaly and colliders in this case must be without spaces between them. This must fix the issue.

Way 3:

Make your own hitting wall logic.

OnColliderEnter you need to get balls velocity. OnColliderEnd you need to set manually velocity.