Search Unity

2018.3 change to Raycast maxDistance behavior

Discussion in 'Physics' started by dgoyette, Dec 15, 2018.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    After updating to 2018.3, I noticed some Raycasting issues where it seemed that I wasn't getting hits when I expected to get them. Digging into this, I found the apparent reason: the Raycast in question was setting distance to 1, and not normalizing the direction vector. Until now, the following were equivalent:

    I used the first approach in some cases as it seemed more performant, since I didn't have to normalize the direction and get its distance. Those are both operations I perceived to be expensive. But under 2018.3, when you say distance: 1, it really means 1. Was this an intended change? Maybe it's something that was fixed in PhysX itself?

    I assume this might be related to the following from the release notes:

    Physics: Fixed an issue where RaycastCommand would yield a wrong result if input ray direction was not normialized. (1035922)​

    However, the release notes specifically mention RaycastCommand, not Raycast, so maybe it's unrelated.

    Anyway, maybe the "result1" approach above was always wrong, but I wanted to see if there was some official response to this. My concern is that the need to normalize the direction and pass in a max distance offsets the performance gains I was hoping for under PhysX 3.4.
     
    Last edited: Dec 15, 2018
  2. It doesn't really matter if you or Unity normalizes the direction vector. I just hope sooner or later Unity will decide if they accept non-normalized vectors as direction or not in all RayCasts uniformly and update the documentation accordingly.
    I would be fine with the normalized vector into direction restriction, because normalization should be done and I can do when I see fit rather than every time when I'm calling the RayCast.
     
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Lurking-Ninja and dgoyette like this.
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Good find. Though the 3.3 docs also stated the same thing (https://docs.nvidia.com/gameworks/c...ry/physx/guide/3.3.4/Manual/SceneQueries.html), despite support for passing in a non-normalized direction and a 'distance' of 1.
     
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Maybe they were normalizing the vector in 3.3, but removed that code in 3.4 as part of the optimization.