# Convertion to Unity not giving same values when only heigh has changed

**URL:** <https://community.cesium.com/t/convertion-to-unity-not-giving-same-values-when-only-heigh-has-changed/28971>\
**Category:** Cesium for Unity\
**Created:** [December 28, 2023, 10:41am UTC](https://community.cesium.com/t/convertion-to-unity-not-giving-same-values-when-only-heigh-has-changed/28971 "2023-12-28T10:41:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando\_Bertezzolo](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/fernando_bertezzolo/32/15280_2.png) [@Fernando\_Bertezzolo](https://community.cesium.com/u/Fernando_Bertezzolo)\
**Post date:** [December 28, 2023, 10:41am UTC](https://community.cesium.com/t/convertion-to-unity-not-giving-same-values-when-only-heigh-has-changed/28971/1 "2023-12-28T10:41:21Z")

</div>

I have a function to convert from Longitude, Laitude and Height and when I call it with same latitude and longitude but different height is giving me differente values in all the coordinates, is this correct?  
This is my function:  
Note there is an adjustment if the height that is coming is below the Y value of the 3DTileSet return the value of the map Y.

```auto
private Vector3 GetUnityPosition(double latitude, double longitude, double altitude)
{
    var height = GeoidHeights.undulation(latitude, longitude);

    
    var pos = new double3(longitude, latitude, height + altitude);
    Debug.Log($" GetUnityPosition: Position {pos}");
    var ecef = CesiumWgs84Ellipsoid.LongitudeLatitudeHeightToEarthCenteredEarthFixed(pos);
    Debug.Log($" GetUnityPosition: ECEF {ecef}");
    var unityPosition = CesiumComponent.GetComponent<CesiumGeoreference>().TransformEarthCenteredEarthFixedPositionToUnity(ecef);
    Debug.Log($" GetUnityPosition: UnityPosition {unityPosition}");
    var position = new Vector3((float)unityPosition.x, (float)unityPosition.y, (float)unityPosition.z);
    var mapPosition = GetMapPosition(position);

    if (position.y > (float)mapPosition.Item2.y)
    {
        return position;
    }
    else
    {
        var newUnityPosition = new Vector3(position.x, (float)mapPosition.Item2.y, position.z);
        Debug.Log($" GetUnityPosition: NewUnityPosition {newUnityPosition}");
        return newUnityPosition;
    }
}

```

These are the logs for two calls with simiar longitude and altitude  
GetUnityPosition: Position double3(-96.7676162719727, 32.8526954650879, 503.441769652035)  
GetUnityPosition: ECEF double3(-632082.156804792, -5326404.26096664, 3440519.35399537)  
GetUnityPosition: UnityPosition double3(24536.5783976775, 451.38818237558, 7897.70696547861)  
GetUnityPosition: NewUnityPosition (24536.58, 451.39, 7897.71)

GetUnityPosition: Position double3(-96.7676162719727, 32.8526954650879, 903.441769652035)  
GetUnityPosition: ECEF double3(-632121.755166528, -5326737.94683391, 3440736.34641859)  
GetUnityPosition: UnityPosition double3(24538.1155527714, 851.384919896722, 7898.2040837938)  
GetUnityPosition: NewUnityPosition (24538.12, 851.38, 7898.20)

Thanks!  
Fernando

---

<div class="post-metadata">

**Author:** ![Brian\_Langevin](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/brian_langevin/32/14490_2.png) [@Brian\_Langevin](https://community.cesium.com/u/Brian_Langevin)\
**Post date:** [January 3, 2024, 6:33pm UTC](https://community.cesium.com/t/convertion-to-unity-not-giving-same-values-when-only-heigh-has-changed/28971/2 "2024-01-03T18:33:01Z")

</div>

Quick sanity check, looks ok to me.

When projecting from WGS84 ellipsoid space (lat long, height) to Unity 3D coords, I think it’s reasonable to expect a height change to change all 3 coordinates in Unity space.

The ellipsoid position you are working with most likely does not have its normal lined up perfectly with Unity’s up (Y axis). This is the only case I can think of where height and Y would move together in isolation.

From what I can tell of your 2 test points, you are changing height only, and Y is mostly affected, with X and Z only changing a little. This suggests that your terrain is georeferenced somewhere pretty close to Unity’s origin, with the terrain’s up _mostly_ pointing in the same direction as Unity’s up (Y). This is the common case for how we expect users to set up a scene. So, looks like you are in the ballpark here.

There’s a great book that covers these concepts too…  
[https://www.virtualglobebook.com/](https://www.virtualglobebook.com/)
