Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Objects go through EdgeCollider2D

Discussion in '2D' started by CookieHCl, Jul 27, 2019.

  1. CookieHCl

    CookieHCl

    Joined:
    Jul 17, 2019
    Posts:
    1
    Unity Version 2019.1.10f1
    Working on 2D

    Status:

    Border: only has EdgeCollider2D(which is square shape)

    Ball: has Rigidbody2D, Circle Collider2D, Script that gives initial force
    • Rigidbody2D: attacked PhysicsMaterial2D (friction = 0, Bounciness = 1) to make it bouncy, changed Linear Drag & Angular Drag to 0, Changed Collision Detection to Continuous
    • Circle Collider2D: attacked PhysicsMaterial2D (friction = 0, Bounciness = 1) to make it bouncy
    • Script:
    Code (CSharp):
    1. Rigidbody2D m_Rigidbody;
    2.     void Start()
    3.     {
    4.         m_Rigidbody = GetComponent<Rigidbody2D>();
    5.         m_Rigidbody.AddForce(Random.insideUnitCircle * 15, ForceMode2D.Impulse);
    6.     }
    I've set Border's layer to Default and Ball's layer to Ball(User Layer 8), and disabled collision between Ball layer and Ball layer at Edit>Project Settings>Layer Collision Matrix, so Balls will not collide each other, but collide with anything else (including Border).

    Exepcted Behaviour:
    Balls bounces inside Border(square shape) with random direction
    Current Behaviour: Balls sometimes go outside Border

    I have no idea why Balls go outside Border.... Is changing Collision Detection to Continuous is not enough? What should I do to make Balls inside Border?