Search Unity

Physics2D.BoxCastAll() doesn't work with direction = Vector2.zero

Discussion in 'Physics' started by Tafk, Apr 25, 2015.

  1. Tafk

    Tafk

    Joined:
    Feb 5, 2013
    Posts:
    20
    Hi, friends.

    Is this intended or bug?

    If it's intended, how can I check if BoxCollider2D intersecting something in the scene? (Without using "event" functions like OnTriggerEnter2D etc.)
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
  3. Tafk

    Tafk

    Joined:
    Feb 5, 2013
    Posts:
    20
    Hi! Thanks for you response.

    Unfortunately, box is rotated and I need to know collision point.

    I created a little test:
    Code (CSharp):
    1.  
    2. Vector2 size = //calculate total size
    3. Vector3 pos = //calculate total position
    4. float angle = //get current angle
    5.  
    6. RaycastHit2D[] hits =  Physics2D.BoxCastAll(pos, size, angle, Vector2.zero);
    7.  
    8. GameObject test = new GameObject("test");
    9. test.transform.position = pos;
    10. test.AddComponent<BoxCollider2D>().size = size;
    11. test.transform.rotation = Quaternion.Euler(0,0, angle);
    12.  
    So basically I'm trying to debug BoxCastAll by creating new object and passing function arguments to the new BoxCollider2D. Test object generates new collider that exactly matches my expecatitions, but BoxCastAll still returns no results (or weird results).
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    It's under unit tests here and passing a direction of zero and using an infinite distance passes fine. There's no bug that I know of.

    I can only presume the code above isn't meant to be working code.

    Anyway, If you've got the time then feel free to create a simple test that reproduces this and submit a bug report. If you pass me the case number then I can take a look at it.
     
  5. Tafk

    Tafk

    Joined:
    Feb 5, 2013
    Posts:
    20
    I've submitted bug report, case number is 692409.
    Please, take a look.
    I'm pretty sure I using something wrong, but who knows.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    I've checked the case and indeed there's a bug which I'm fixing right now. I'll get this into the next patch release for 4.x and 5.x releases. These come out weekly.

    Thanks for the bug case and sorry for the problem.
     
  7. Tafk

    Tafk

    Joined:
    Feb 5, 2013
    Posts:
    20
    Nice!
    Glad I could help :)
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    Just a heads-up to say that this fix has now been merged to both 4.6.5p1 and 5.0.1p3 (patch releases) that will be release soon.

    Note that for it to detect objects that immediately overlap the shape (box/circle), you'll need to ensure that the Physics2D.raycastsStartInColliders is checked.