Search Unity

RaycastHit2D hit.normal returns error when hit.transform.rotations is not 0

Discussion in 'Physics' started by Aldo, Sep 23, 2015.

  1. Aldo

    Aldo

    Joined:
    Aug 10, 2012
    Posts:
    173
    Hello everyone, I saw something weird when having objects rotated 90°, 180° & 270°

    I am making a raycast:

    Code (CSharp):
    1. Physics2D.RaycastHit2D(rayOrigin, transform.up * directionY, rayLength, collisionMask);
    After that I am checking the normals, simple:

    Code (CSharp):
    1. if ( hit.normal.y < 0 || hit.normal.x < 0)
    2.     Do Stuff
    The if clause is being activated even when it should not be. So I started debugging:

    Code (CSharp):
    1. if (hit.normal.y < 0)
    2.                             Debug.Log("normal.y: " + hit.normal.y * 1.000f);
    3.                         if (hit.normal.x < 0)
    4.                             Debug.Log("normal.x: " + hit.normal.x * 1.000f);
    And I am getting X or Y as an error ONLY on platforms that had been rotated. (this test was only on X but the problem comes on both)

    normal.x: -3.45707E-07
    normal.x: -3.576279E-07

    I can check the normal and make the error go to zero, still I would like to know if anyone knows why this happens.