How do I find the height information given x and z of the Cesium Map

Hi, I want to spawn prefabs using a C# scripts at a specific location on the map. I have the x and z World coordinate but I need to figure out the height (World y coordinate). I tried using Raycasting to no avail. Is there a built-in Cesium function (Return Height) for this?

Thanks

Call it via a web component using a web service that will echo back the altitude for that location.

Could you provide the exact reference of the function of the Cesium API?

Thanks.

https://cesium.com/learn/cesiumjs/ref-doc/HeightReference.html

I don’t think you can get this value inside Cesium for Unity. You will therefore have to call it via a third party (https://www.geonames.org/) webservice and then use that value for your spawned objects’ altitude. However, you will have to calibrate an offset in relation to the actual surface.

Raycasting is the only built-in option currently. If you elaborate on “no avail” there’s a chance we might be able to help.

Calling an external web service could be a good option, too, though I can’t help you with the specifics on that.

What I tried was to shoot a ray vertically (I tried both directions: up and down) and tried to find the intersection point with the Cesium map. Assume x_center and z_center to be 0 and 0 in the world space. Assume that the Cesium map is somewhere around y= - 2000

    float x_random = Random.Range(x_center-cell_size/2, x_center+cell_size/2);
    float z_random = Random.Range(z_center-cell_size/2, z_center+cell_size/2);
    Vector3 origin = new Vector3(x_random, -1000000f, z_random); // Start the raycast from a high point
    Vector3 direction = Vector3.up;
    Ray ray = new Ray(origin, direction);
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit, 10000000000000))
    {
        return hit.point.y;
    }

This doesn’t yield any intersection.
Thank you for your help.

Hi @beepboop,

Just to be sure, can you confirm that you have “Create Physics Meshes” enabled on the tileset?

If that is enabled, and this still isn’t working, can you share when exactly you’re casting the ray? 3D Tiles will take a few frames to stream in, so raycasting at the beginning of the application is essentially raycasting into empty space. The tiles need to load into the scene before you can raycast against them.