Search Unity

Boxcast Hit things, but return invalid normal.

Discussion in 'Physics' started by canis, Apr 19, 2020.

  1. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    I'm using boxcast hit, and sometime this happen to me, any ideas ? (as image),

    raycastHit_normal_nan.PNG

    right now I'm trying to avoid this issue by check if the value IsNaN, for everytime Boxcast said it hit something.
    but I can't 100% reproduce this, it append random on same code.
     
  2. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    turn out the reason was the box size.
    I try to detect the surface collision by using
    Code (CSharp):
    1. new Vector3(float.Epsilon, 10f, float.Epsilon);
    this issue will appear if using float.Epsilon in the size reference,
    it's able to reproduce by specific coordinates & distance.

    Note : not all of them, but some of them, however when you located it can always reproduce in same position.
    In my case I use Gizmos draw to debug.

    I guess the glitch happen during the normal vector calculation :
    was the input "float.Epsilon" being divide by something and round down become zero.
    and that being used as divisor.​

    so the solution for me was simply change Epsilon to "0.0001f".... a small enough number for my calculation.
     
    Last edited: Apr 26, 2020