Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to determine height at a specific location #436

Open
rslonake opened this issue Apr 27, 2024 · 2 comments
Open

How to determine height at a specific location #436

rslonake opened this issue Apr 27, 2024 · 2 comments

Comments

@rslonake
Copy link

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
Copy link
Owner

Zylann commented Apr 27, 2024

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 #300

@rslonake
Copy link
Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants