- Home /
Smoothly deform terrain
Hi, I created a dig method for my terrain, which is supposed to decrease each point on the terrain within a certain radius x amount of units. It works, but when the hole becomes steep, random vertices begin popping up, probably in an effort to smooth out the terrain. How can I stop this? Here is my method :
Vector3 tPos = transform.position;
TerrainData tData = GetComponent<Terrain>().terrainData;
Vector2 digPoint = new Vector2();
digPoint.x = ((point.x - tPos.x) / tData.size.x) * tData.heightmapWidth;
digPoint.y = ((point.z - tPos.z) / tData.size.z) * tData.heightmapHeight;
float[,] heights = new float[radius, radius];
for (int i = 0; i < radius; i++)
{
for (int j = 0; j < radius; j++)
{
int x = (int)digPoint.x + i;
int y = (int)digPoint.y + j;
float newHeight = Mathf.Max(tData.GetHeight(x, y) / tData.size.y - depth * Time.deltaTime, 0f);
heights[i, j] = newHeight;
}
}
tData.SetHeights((int)digPoint.x, (int)digPoint.y, heights);
Any help is appreciated!
Answer by hexagonius · Jan 16, 2016 at 05:12 PM
I found this method which essentially ignores the LOD update :)
http://docs.unity3d.com/ScriptReference/TerrainData.SetHeightsDelayLOD.html
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
[BEGINNER] Generating Terrain with Perlin noise flat and nothing happens ? 1 Answer
Problem with blending two terrains together on an edge. 1 Answer
Edit Terrain at runtime 1 Answer
Terrrain Texturing with solid colors,Terrain texturing with solid color tile 0 Answers