- Home /
Physics2D.Raycast returns incorrect normal when casting from inside collider
When I cast a ray from inside a collider I get a wrong normal in the RayCastHit2D structure (Always (1,0)). I know there exist a check box in preferences that reads "Queries Start in Colliders", but this is not the issue because I need to detect collisiosn when casting inside a collider. But I need the normal to be the correct one :).
Is this as intended or a bug in unity?
CHeers.
It returns {1,0} because normal is meaningless it that situation. Think again which normal do you need exactly. $$anonymous$$aybe you just need to replace it with different vector in that situations:
raycast.direction * -1
Or:
( raycastOriginPosition - otherCollider.transform.position ).normalized
Etc.
Answer by MelvMay · Apr 19, 2018 at 02:47 PM
It would probably help to describe what you mean by "But I need the normal to be the correct one.".
Anway, if you're expecting to be able to perform a raycast from inside a closed shape like a Cirlce, Box or Polygon and get the interior edge then you're out of luck as that won't work. These are not simply edges but closed shapes. You can intersect from the outside-in but not the inside-out. A raycast will contact any of the interior at the start of the ray and the normal is just related to the direction of the ray because there isn't a real normal so it's kind of degenerate.
The option you refer to simply allows you to control whether starting inside a collider is ignored completely or not.
Only EdgeCollider2D can be hit from both sides as it's an open shape and has no interior.
Your answer
![](https://koobas.hobune.stream/wayback/20220612155736im_/https://answers.unity.com/themes/thub/images/avi.jpg)