- Home /
Physics2D.BoxCast detects inexisting collisions!?
Hey there,
I've been having weird results with Physics2D.BoxCast so I made a minimal scene to test it up and I'm puzzled.
You can see on the picture, I have 2 simple GameObjects, each with a RigidBody2D and a BoxCollider2D. The big one on the top left is separated from the little one on the right by 0.0062 world units, they do not overlap. Yet, when I try to see if I can safely move the little box further to the right without running into the big box, I'm running these lines:
BoxCollider2D collider = GetComponent<BoxCollider2D> ();
RaycastHit2D hit = Physics2D.BoxCast (collider.bounds.center, collider.bounds.size, 0f, Vector2.right,.5f);
And I get a hit! Which you can see marked in red in the picture (I used Debug.DrawLine).
When I test if the two colliders overlap (using Physics2D.IsTouching), they don't, but when I try moving them further apart, I get a collision right in between both (in a spot that isn't even part of the supposedly touched collider...)
In my test case, the problem occurs when the two colliders are separated by 0.0062 at most. Once separated by 0.0063, I no longer get a hit with the BoxCast...
Does anyone have any idea about what could cause this, am I getting crazy, am I doing something wrong or does this call for a bug report?
Thanks a lot for any information or help anyone could give me.
I have run into almost exactly the same problem. I've been beating my head against my keyboard all day trying to figure out why my boxcast movement script keeps sticking to walls when the distance drops below 0.006 units without actually touching, and apparently it's not my code! Did you ever find any sort of workaround?