# Picking on terrain

**URL:** <https://community.cesium.com/t/picking-on-terrain/6878>\
**Category:** CesiumJS\
**Created:** [May 4, 2018, 12:48pm UTC](https://community.cesium.com/t/picking-on-terrain/6878 "2018-05-04T12:48:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeller.alexandersamu](https://avatars.discourse-cdn.com/v4/letter/z/3be4f8/32.png) [@zeller.alexandersamu](https://community.cesium.com/u/zeller.alexandersamu)\
**Post date:** [May 4, 2018, 12:48pm UTC](https://community.cesium.com/t/picking-on-terrain/6878/1 "2018-05-04T12:48:11Z")

</div>

Hey there,

I´m trying to get the position of a mouseclick including the terrain height. So imagine this. The camera is close to the ground and pointed towards a mountain. If I click on the mountain I want to get the mosition on the mountain. I was able to get this working but with one problem.

If the click position (so, for example a mountain top) has the ellipsoid behind it its all working fine. I get the height and the correct position. But if I rotate the camera enough so that behind the mountain top there is the horizon (or rather space) I get an error even though I am still clicking on terrain. Hope this was clear enough.

Heres the gist for a sandcastle example  
: [https://gist.github.com/AlexZeller/1452287607b0d1fad642bc3111bc531d](https://gist.github.com/AlexZeller/1452287607b0d1fad642bc3111bc531d)

Thanks for your ideas

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [May 8, 2018, 2:42pm UTC](https://community.cesium.com/t/picking-on-terrain/6878/2 "2018-05-08T14:42:39Z")

</div>

It sound like you are picking the ellipsoid and not the terrain itself, that’s why you are getting undefined when you are picking the space behind the mountain and not on the ellipsoid.

Try using **[Scene.pickPosition](https://cesiumjs.org/Cesium/Build/Documentation/Scene.html#pickPosition)** instead of **Scene.globe.pick** , as it uses the depth buffer to select the position.

Thanks,

Gabby

---

<div class="post-metadata">

**Author:** ![zeller.alexandersamu](https://avatars.discourse-cdn.com/v4/letter/z/3be4f8/32.png) [@zeller.alexandersamu](https://community.cesium.com/u/zeller.alexandersamu)\
**Post date:** [May 9, 2018, 8:01am UTC](https://community.cesium.com/t/picking-on-terrain/6878/3 "2018-05-09T08:01:55Z")

</div>

That was it.

Thank you!
