Unity - Adjust terrain heights at world position

  • Posted on: 16 February 2015
  • By: admin

My brother and I struggled to find some information on this adjusting terrain heights at a specific world position, so once we figured it out I thought it might be worth posting.

I hope this helps someone else.

// Some random world position ( y is ignored ) 
Vector3 worldPosition = new Vector3(10f,0f,10f); 
Vector3 heightMapScale = terrain.terrainData.heightmapScale; 

// The rectangle size we want our terrain height adjustment. 
int size = 30; 

// Grab the active terrain and the heights at our size 
if(Terrain.activeTerrain != null) { 
  Terrain terrain = Terrain.activeTerrain; 
   * Convert from world position to terrain height maps. 
   * This subtracts any offset in the terrain position from the world postion, 
   * divides that by the heightmapScale to convert it to heightmap x,z coordinates, 
   * and then subtracts the middle of our position size so that it will be centered over the spot we chose. 
   * Also, the int conversion happens at the end because the SetHeights call expects ints for the x and z. 
  int xPosition = (int)((worldPosition.x - terrain.transform.position.x) / heightMapScale.x - (size / 2)); 
  int zPosition = (int)((worldPosition.z - terrain.transform.position.z) / heightMapScale.z - (size / 2)); 

  // Grab the original heights 
  float[,] heights = terrain.terrainData.GetHeights(xPosition,zPosition,size,size); 

  // Now loop and set heights 
  for (int z=0; z<diameter; z++) {
    for (int x=0; x<diameter; x++) {
      // Set the height.  Converted to heightmap height
      heights[z,x] += 1f / terrain.terrainData.heightmapHeight;

  // Now set the heights


Unity - Automated Scene Builder Demo

  • Posted on: 6 February 2015
  • By: admin

We just released the Automated Scene Builder for Unity in the Asset Store.  Here's a quick demo.

We will be adding some more documentation in the blog section in the next few days.