- Home /
Question by
Kourosh · Oct 07, 2010 at 08:40 PM ·
terrainterraindata
terrainData SetHeights/GetHeights?
I want to sample an area of 100x100 from a huge reference terrain and apply the terrainData to a samll 100x100 terrain. I have no idea how to use SetHeights and GetHeights. Any enlightening guidance:) thanks,
Comment
Answer by IBDelta · Mar 03, 2011 at 03:56 PM
This code shows how to get the height of the terrain at a certain point and then instantiate an object just above that point.
void TankPlace()
{
Vector3 TankPosition=Vector3.zero;
Quaternion TankQuat = Quaternion.identity;
int TankRotY=0;
float TankY=0.0f;
TankPosition=new Vector3(250.0f,TankY,250.0f);
TankY = Terrain.activeTerrain.SampleHeight(TankPosition);
TankPosition=new Vector3(250.0f,TankY+1.0f,250.0f);
TankRotY=Random.Range(0,360);
TankQuat.eulerAngles=new Vector3(0,TankRotY,0);
NewTankPrefab = Instantiate(TankPfb, TankPosition, TankQuat) as GameObject;
}