Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Ball bounce in the edge of the collider

Discussion in '2D' started by asraaalatme, Jun 23, 2022.

  1. asraaalatme

    asraaalatme

    Joined:
    Apr 23, 2022
    Posts:
    3
    I'm making a brick breaker game I have an issue. when the ball bounces to a brick, it will bounce to the opposite site again Take a look

    notice my bricks don't have gaps between each other so the ball shouldn't behave like this






    my setup

    Bricks

    • have a boxCollider2d
    • important: there are no gaps between those bricks
    • using TileMap for drawing the bricks
    Ball

    • have a circleCollider2d
    • ridgedbody with a velocity
    • bounce material (no fraction)
    I'm happy to listen to any suggestions from you guys.
     
  2. asraaalatme

    asraaalatme

    Joined:
    Apr 23, 2022
    Posts:
    3
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    Does the Rigidbody use continuous collision? If not, it may be completely missing the left block in your sketched example.

    ALSO: huge props for drawing the diagram ... pictures are awesome, even sketches in a paint program!
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,620
    As per your diagram, the physics system doesn't see things that are "lined up" as a continuous single surface. It might see a contact with the corner of the right box so rebounds from it appropriately even if it isn't what you want.

    If these things are logically grouped together and there's not thousands of them then you might still get good performance by using them grouped into the same CompositeCollider2D (or multiple ones for multiple joined groups). This collider has an "outline" mode which creates continuous surface edges.

    Just be careful because whilst it's fast adding/removing individual colliders, it gets more expensive the more geometry added to it. This is something you can test via the profiler on your device(s) though.
     
    asraaalatme likes this.
  5. asraaalatme

    asraaalatme

    Joined:
    Apr 23, 2022
    Posts:
    3
    thanks for responding
    i manage to fix it by change the boxColider2d to a EdgeColider2d its work as i wanted
    but i face a huge drop of frames when many balls collide with the bricks
    then i changed the EdgeColider2d to PolygonCollider2D but sometimes the balls behave like before but that is ok with me so I leave it like this for now