all Physics2d.Boxcast variants are broken

Physics2D.BoxCast
Physics2D.BoxCastAll
Physics2D.BoxCastNonAlloc

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

Consider the following code

var size = new Vector2(1,1)
var angle = 0f;
var distance = 5f;
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

var size = new Vector2(1,1)
var angle = 0f;
var distance = 5f;
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

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

As with all bugs, please file a bug report with a repo project if you can.

1 Like

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.