Zylann / godot_heightmap_plugin

HeightMap terrain for Godot implemented in GDScript
Other
1.71k stars 159 forks source link

How to determine height at a specific location #436

Open rslonake opened 4 months ago

rslonake commented 4 months ago

Is it possible (via script) to determine the height parentheses y-coordinate given an x-coordinate and a z-coordinate?

In other words, if I provide an X and Z can I return the Y?

Zylann commented 4 months ago

You can use functions on the HTerrainData resource, which is available on the data property of the terrain node. There is get_height_at and get_interpolated_height_at. They expect coordinates in local space though, and return the height in local space as well, so you may have to convert them back to world space if you scaled the map with map_scale or the node's transform. get_internal_transform() may be used to convert between cell space and world space.

Alternatively, the terrain node has a cell_raycast method to raycast the ground in world space, though it returns 2D coordinates in cells. A regular physics raycast would also give you that.

See also https://github.com/Zylann/godot_heightmap_plugin/issues/300

rslonake commented 4 months ago

Thank you.