0 votes

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/hterraindata.gd" there is a function called: 'getheight_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 :)


Godot version 3.4
in Engine by (39 points)

1 Answer

0 votes
Best answer

So "getheightat()" 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.

by (39 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.