- Home /
the terrain rises and lowers automatically
how can I do that in certain parts of the land, the land rises and lowers automatically ?
Comment
Take a look at Terrain and the TerrainData class in the script reference, more specifically the SetHeight function
I need that the land rises and lowers automatically continuously without stopping
Answer by aldonaletto · Nov 23, 2013 at 02:34 PM
If you want to move the entire terrain up and down, a simple solution is to control its transform.position (attach this script to the terrain):
public range: float = 0.5; // how much terrain swings up and down (meters)
public speed: float = 6.28; // 6.28 * cycles per second
private p0: Vector3;
function Start(){
p0 = transform.position;
}
function Update(){
transform.position = p0 + Vector3.up * range * Mathf.Sin(speed * Time.time);
}
But things are way more complicated if you want to move only parts of the terrain: you must somehow define the region you want to move, get the current heights in this region in an square array with GetHeights, modify and assign them back with SetHeights.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122522im_/https://answers.unity.com/themes/thub/images/avi.jpg)