I’m using this code to tilt my terrain at runtime. It works pretty well except it’s very slow. It has to iterate through each height point so it ends up taking 2-3 seconds. I’d love to find a way to shave even a little bit of time off.
function OnGUI ()
{
if (GUI.Button(Rect(200,10,50,30), "tilt"))
{
SlopeAngle (0.1);
}
}
function SlopeAngle (change : float)
{
var tData = terrain.GetHeights(0, 0, terrain.heightmapWidth, terrain.heightmapHeight);
// iterate through height points
for (i = 0; i < terrain.heightmapHeight; i++)
{
for (j = 0; j < terrain.heightmapWidth; j++)
{
// lowers terrain points at end, gradually decreasing to 0 as it reaches end
tData[i, j] -= ((change / terrain.heightmapWidth) * j);
}
}
terrain.SetHeights(0, 0, tData);
}