[Unity] How to get terrain elevation from Cesium3DTileset to prevent objects rendering below ground

Hi Cesium team,

I’m using Cesium for Unity (v1.16.1) with Unity Hub 3.8 to visualise 3D terrain using a Cesium3DTileset.

Problem

When placing objects using georeferenced coordinates (longitude, latitude, height), I often find that the objects are rendered below the terrain surface, especially when the height is close to ground level.

I would like to:

  • Sample the terrain elevation at a specific longitude and latitude
  • Adjust my object’s height so that it sits exactly on top of the terrain
  • Prevent rendering issues where the object appears buried underground

My Questions

  1. Is there a recommended way in Cesium for Unity to get terrain elevation at a specific location?
  2. Can I add colliders or otherwise access the terrain mesh height directly?
  3. What are the best practices for accurately placing objects on top of Cesium terrain?

Thanks for your support!

@deet_dev You’ll want to give SampleHeightMostDetailed a try. You can use it from a coroutine like:

// height is ignored
var task = tileset.SampleHeightMostDetailed(new double3(longitude, latitude, height));
yield return new WaitForTask(task);
CesiumSampleHeightResult result = task.Result;
if(result.sampleSuccess) {
    // result.longitudeLatitudeHeightPositions will contain the positions with heights sampled from the tileset
}