Hello guys,
I am stuck with an apparently simple problem:
How can I get the height of a Landscape at a certain x,y coordinate in c++?
Any help is hiiighly welcome
Greez, Alex
Hello guys,
I am stuck with an apparently simple problem:
How can I get the height of a Landscape at a certain x,y coordinate in c++?
Any help is hiiighly welcome
Greez, Alex
Not aware of any built-ins to get position of landscape at a location.
You could do a ray trace on a channel like visibility and get the transform at where the hit happens.
Hi Boarnoah. That is a possibility. Yet I need the position of each vertex (x,y) and the height information of the heightmap. With tay trace I do not know where a Landscapevertex is.
Hi i do you able to solve this problem? If yes would you mind share how u got the coordinate for the Landscape vertices.
FVector UBPFunctionLibrary::BPGetGroundPoint(UObject* WorldContextObject, FVector VectorNeedToAdjust)
{
if (!WorldContextObject)
return VectorNeedToAdjust;
UWorld* World = WorldContextObject->GetWorld();
if (!World)
return VectorNeedToAdjust;
AActor* LandActor = UGameplayStatics::GetActorOfClass(WorldContextObject, ALandscape::StaticClass());
ALandscape* Land = Cast(LandActor);
if (Land)
{
TOptional Height = Land->GetHeightAtLocation(VectorNeedToAdjust);
if (Height.IsSet())
{
return FVector(VectorNeedToAdjust.X, VectorNeedToAdjust.Y, Height.GetValue());
}
else
{
UE_LOG(LogTemp, Warning, TEXT(“Height value is not set for location: %s”), *VectorNeedToAdjust.ToString());
}
}
return VectorNeedToAdjust;
}
/*
Here’s my code. It takes an input vector with an incorrect height and outputs a coordinate that aligns perfectly with the ground. I think it works really well and is more elegant than using ray tracing! If you want to use this code, make sure to include the Landscape module. Hope it helps!
*/