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. Dismiss Notice

Bug all Physics2d.Boxcast variants are broken

Discussion in '2021.1 Beta' started by astrokoala, Mar 12, 2021.

  1. astrokoala

    astrokoala

    Joined:
    Mar 23, 2016
    Posts:
    22
    Physics2D.BoxCast
    Physics2D.BoxCastAll
    Physics2D.BoxCastNonAlloc

    these are all broken, that never takes distance parameter into account.

    Consider the following code
    Code (CSharp):
    1. var size = new Vector2(1,1)
    2. var angle = 0f;
    3. var distance = 5f;
    4. Physics2D.BoxCastAll(origin, size, angle, Vector2.down, distance, layers);
    this code will fail to detect anything within the 5 distance, and will only detect something touching that 1 x 1 size

    in contrary to this code
    Code (CSharp):
    1. var size = new Vector2(1,1)
    2. var angle = 0f;
    3. var distance = 5f;
    4. Physics2D.CapsuleCastAll(origin, size, CapsuleDirection2D.Vertical, angle, Vector2.down, distance, layers);
    the capsule cast version works properly and correctly detects everything in 5 distance away
     
  2. astrokoala

    astrokoala

    Joined:
    Mar 23, 2016
    Posts:
    22
    To anyone having the same problem
    and to the unity team

    I found that if you change the
    Default contact offset
    setting in Project Settings/physics2d
    from
    0.001
    (the default value) to
    0.01
    , it then starts to work properly

    Please take a look into this
     
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    As with all bugs, please file a bug report with a repo project if you can.
     
    LeonhardP likes this.
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,106
    Hi @astrokoala,

    Based on your description of the problem we couldn't find anything wrong. If you're still affected by this problem, as @Chris-Trueman suggested, please submit a bug report with a reproducible so we can have a look at your exact use case.
     
  5. TheAliasNine

    TheAliasNine

    Joined:
    Jun 29, 2021
    Posts:
    1
    I have run into the same issue and I have found that the bug is dependent on what the scene starts with the default contact offset is.
    What I have found is
    • if you start the scene with an offset above 0.0024 the bug will not occur
    • if you start the scene with an offset of between 0.0024 & 0.00125 the bug does not occur until the offset is below 0.00125 and will stop when you set it back to above 0.00125. Weirdly enough though if you start on 0.00125 then lower it down to 0.00124 or 0.00123 then change it back to 0.00125 then the bug remains until changed above 0.00125
    • if you start the scene with an offset below 0.00125 then the bug occurs until the offset is above 0.0024
    I tested this by changing the value through the editor and pausing while changing it. I will start to make a bug report tonight but I may be interrupted before completing it.