How to read landscape heightmap at runtime?
I want to read Landscape altitude (z value) given 2D coordinates (x and y values) from another actor at runtime.
LandscapeProxy::GetLandscapeInfo()->XYtoComponentMap()[x,y]->HeightmapTexture->GetSurfaceHeight() or should I look somewhere else? anyway I'm not even sure about resolution of this value (does it returns the average height of the tile? the maximum?) Is there a way to find the exact z value?
All of this because I want to spawn an actor just a few meters above the terrain. I guess there is an easier way to do that...
I recently had a similar problem and stumbled across this post. Now I have found a solution, so here it is:
First you need to somehow get an instance to your landscape (assuming you only have one in your level):
Now you can do a line trace where you only look at the landscape and no other object in the scene. The internal physx collision object is initialized from the heightmap data, so this line trace should be very fast and in theory it should have almost the same speed as doing a heightmap lookup:
answered Oct 25 '14 at 04:32 PM
answered May 08 '15 at 07:01 PM
SND R Keene
I know this is Unreal Engine, but when i was unity, the landscape had a mesh component. So try getting a reference to the mesh component of the landscape. It should have some kind of property that you can get the z component, given an x-y coordinates.
Edit: Ill try it out when i get home on my project.
Follow this question
Once you sign in you will be able to subscribe for any updates here