Raycasts are broken on Terrain LoD

I noticed this issue yesterday while working on a new raycast-based turret system for a tank vehicle in one of our games, Glacier.

However, this issue may have existed for a long time, and may have been the culprit of many other bugs our team had encountered over time during development.

It appears that raycasting is completely broken on terrain that is under the effect of LoD (e.g. streamed terrain), and will report the terrain as non-existent.

This is bad for many reasons:

  • All local systems that rely on raycast cease to function when casting at this terrain
  • There is no compatibility between the visual aspect and functional aspect of the terrain, as the player is seeing terrain but the scripts are not
  • Harmful for gameplay, specially in large map games or shooters

In Glacier, this bug is very disruptive to gameplay, causing players and vehicles to get hit through terrain cover, incorrect depth of field calculations (that is, the distance check), incorrect turret angles at long distances, impossibility of smooth artillery and other types of long-distance mechanisms that rely on the client.

Expected behavior

Raycasts should function the same as normal in all terrain, even LoD terrain.
It’s understandable that the quality of the raycast would be smaller, but for the raycast to be completely impossible does not make sense. This is a problem for open world games for the reasons described above and possibly more.

Additionally, the raycasts begin to work as normal again once the terrain is loaded in (by going close to the terrain).

REPRO
I have made a quick reproduction place where you can experience the problem.
The steps are really simple: spawn in, point your cursor at distant terrain (or just overall terrain that looks like it is at a lower quality level) and watch the debug data on the left.

Terrain LoD raycast bug repro.rbxl (9.9 MB)

6 Likes

This is longstanding behavior, but something that needs to change. Inaccurate LoD’d raycasts are better than no raycasts.
We’ll look into it.

8 Likes