Determine a radius on terrain and lerp the border to smooth the height flattening
I know it looks like a complex question so here's what I'm doing. Currently I can determine an area, get the terrain heights in that area, filter the results to fit inside a circle and then set a flat height to those. Which gives me the 2nd result in the image. Just a flat height inside a circle.
Question is, how can I smooth the height around that circle so that it looks like number 3? My math check cannot roll high enough for this battle :)
My Current code:
float[,] heightsAroundBuilding =
_mainTerrainData.GetHeights(terX - radius/2, terZ - radius/2, radius, radius);
float heightScale = 1.0f / _mainTerrainData.size.y;
for (int i = 0; i < radius; i++)
{
for (int j = 0; j < radius; j++)
{
float heightToSet = (spawnPosition.y - heightOffset) * heightScale;
if ((i - radius / 2) * (i - radius / 2) + (j - radius / 2) * (j - radius / 2) < radius * 2)
{
//SMOOTHING LOGIC HERE probably via lerp?
heightsAroundBuilding[i, j] = heightToSet;
}
}
}
_mainTerrainData.SetHeights(terX - radius/2, terZ - radius/2, heightsAroundBuilding);
Comment