How to get altitude above terrain

I’m trying to build a simple flight simulation game, I have my own Flight Model and I created a C++ class that receive the current position and attitude from my Flight Model.

In order to be able to land, I need to know the altitude above terrain to understand when I’m getting closer to it.

With the following blueprint I’m able to get the altitude from sea level. (MRMask is the actor representing my aircraft)

But how can I get the altitude over the terrain?

Hi @Raffaele_Bortoli, welcome to the forum!

I would recommend doing a Line Trace from your plane actor down towards the terrain. This page includes some useful information about line traces. When the line trace hits something, you can use the Out Hit location and transform that location into longitude/latitude/height. The z vector of the result will be the altitude at the location queried.


Thank you Alex,

I manage to get it to work, I followed the instruction from the “Line Trace” example, but I simplied the computation by providing the second point for Hit Detection via C++, I’m using UE5 and the vector approach was not working exactly as supposed to be.


@Raffaele_Bortoli, glad to hear you got it working!

If you’re able, please consider sharing more information about your C++ implementation to help others out in the future.


@agallegos of course.

Here is the Blueprint I ended up with:

in which I’m providing from “FlightController” object a point that has the same coordinates of my 3D object (MRMask) with the exception that I’m providing an altitude that is 1000m below the ground, this is to avoid a problem I had on producing a vector pointing to the ground.

In the C++ code beyind the “FlightController” object with this simple code I’m updating the position of the MRmask and “Test Point 1”,

glm::dvec3 UECoords = this->CesiumGeoreference->TransformLongitudeLatitudeHeightToUnreal(glm::dvec3(sim_status->Longitude, sim_status->Latitude, sim_status->Altitude));

			glm::dvec3 t1 = this->CesiumGeoreference->TransformLongitudeLatitudeHeightToUnreal(glm::dvec3(sim_status->Longitude, sim_status->Latitude, -1000));
			TestPoint1.X = t1.x;
			TestPoint1.Y = t1.y;
			TestPoint1.Z = t1.z;

			MRMask->SetActorLocation(FVector(UECoords.x, UECoords.y, UECoords.z));
1 Like