godot_heightmap_plugin
godot_heightmap_plugin copied to clipboard
how can i query the height of the terrain (while i'm in editor mode), or how can i get "cell_raycast" to work?
Hi
Thanks for your awesome plugin. I really want to be able to query a height somewhere for the sake of placing trees etc by code.
I couldn't find any documented featrues to probe the terrain but notes in the code.... all i seem to be able to get back from cell_raycast is null, i look through it i wondered if it's even finished or working?
There are multiple ways to do that.
- Using a physics raycast. First make sure the collider is up to date by selecting the terrain and in the Terrain menu, choose "Update collider" https://hterrain-plugin.readthedocs.io/en/latest/#collisions. This is what my scatter plugin uses https://github.com/Zylann/godot_scatter_plugin/blob/79940dbe0c6c1b5762eee702bc30f6d932e70a8f/addons/zylann.scatter/tools/plugin.gd#L161
- Using cell_raycast (it has types and a documentation comment in code, I recommend looking it up. Even if API docs existed for the plugin, thats the same thing you'd see in there): this one is specific to the heightmap and will only detect the heightmap. This function should work because it's what the plugin uses for everything in the editor. I don't know what you tried, but all it takes is a ray as a begin world position, a direction unit vector, and a maximum distance. It's used here for example: https://github.com/Zylann/godot_heightmap_plugin/blob/e51c544cd8282bae83ba4ef0fc10884e9216d37a/addons/zylann.hterrain/tools/plugin.gd#L449
If you get
nullall the time it probably means you are not giving the right arguments?
thanks for the info, i think i will have this worked out soon by looking at this code