- Home /
Why does Physics2D.Capsule/Circle/BoxCast's hit point and distance not line up?
I've started writing a 2D character controller, and am making use of Physics2D.CapsuleCastNonAlloc to simulate movement before updating the transform. I've noticed that the point returned is 0.05 units higher than the actual edge, and what's weirder, the RaycastHit2D.distance value returned is not the same as if I do Vector2D.Distance on the point and the edge of my circle collider (position - (direction * radius). Even weirder than that is the difference between the two is always approximately 0.0075, no matter the distance or radius of the circle or direction of the cast/ground. I've tested in 2018, 2017, and even 5.6.
If I use the 3D counterparts, it works perfectly and I get a distance of exactly 0.5 as I expect, with the point right on the edge. If I use a simple 2D Raycast, it works. Something about 2D casting feels wrong and I don't know if it's intended. Has anyone experienced this or know what the deal is? It seems wrong to adjust the value myself by 0.0075 to get true points/distances, or to substitute with a 3D cast in a 2D world.
Your answer
Follow this Question
Related Questions
Raycast2D Layermasks and incomplete docs 1 Answer
why are child colliders sometimes ignored? 2 Answers
2D - How can I create an "inverted" circle collider? 1 Answer
HingeJoint with no rotation? 0 Answers
Raycasting 1000 times 1 Answer