HTerrain plugin -> get height of x,z position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By spinland

Does anyone know how to get the y position of my terrain’s mesh (ground height)? I’m using HTerrain plugin.

in “res://addons/zylann.hterrain/” there is a function called: ‘get_height_at()’ that says it gets the non-scaled height of x,z…but it doesn’t seem to be working properly even when I factor in the terrain map scale.

I know this plugin can do this as places grass on my terrain perfectly according to height…I’ll look into that functionality and maybe find something…

If anyone knows how to do it tho, that’d save me a lot of time :slight_smile:


:bust_in_silhouette: Reply From: spinland

So “get_height_at()” works it’s just not scaled. I thought this meant that the returned float wasn’t scaled which it isn’t but it also means that what you put in for x and z need to be non scaled to. So here is my working code.

var y = $HTerrain.get_data().get_height_at(x / map_scale, z / map_scale) * map_scale

This seems to work. Although I’ve only tried on a few test objects.