Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Adjust Terrain edges

Discussion in 'Scripting' started by simone007, Jul 7, 2010.

  1. simone007

    simone007

    Joined:
    Oct 30, 2008
    Posts:
    221
    Hello to everyone,
    I need your help to solve a problem with a terrain I am using in my project.

    I have a terrain of dimensions 900x600. I need to change it so that the borders of the terrain smoothly lowers to height=0

    Here's a screenshot of a border of my terrain:


    And here's another terrain (not mine) with terrain heights that lowers at the edges:



    My question is: is there a way to achieve these smooth edges automatically or programmatically?
     
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    Why would you make a terrain so it has a hill at the edge when you could just create your hills/mountains at the center and leave the edges at 0? What kind of borders are you using?
     
  3. simone007

    simone007

    Joined:
    Oct 30, 2008
    Posts:
    221
    I need to be free to build a terrain as I desire. In my game there will be a lot of different terrains, so it would be ugly to have all terrains flat at the edges. And.... I really love those smooth borders ;)
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Fractscape has an option to clamp terrain borders to a given height.

    --Eric
     
  5. simone007

    simone007

    Joined:
    Oct 30, 2008
    Posts:
    221
    Hmmm... nice idea. Can you please tell me if the clamp operation is smooth and if I can use fratscape on my already existing terrains? I am curious and I've got no time today to test it
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The clamp operation looks like the attached screenshot, and you can use pre-existing heightmaps. Although you do have to give it at least a little leeway for randomization--if you use the exact same resolution for the heightmap as the terrain, then the edge clamping isn't smooth.

    --Eric
     

    Attached Files:

  7. UnityGISTech

    UnityGISTech

    Joined:
    May 6, 2015
    Posts:
    193
    i spent alot of time to get my dynamic terrain works bet every time i have spaces between terrains tiles any one can help me please :

    my code :
    note that map size is the number of col and row

    public float[,] _floatheightData;
    // Here where i have all elevation data stored from parsing elevation file



    Code (CSharp):
    1. where i have all elevation data stored from parsing elevation file
    2. Code (CSharp):
    3.  
    4. public float[,] GetTileHeightMap(TerrainPrefs prefs,TerrainData tdata)
    5.     {
    6.         if (_floatheightData.Length > 0)
    7.         {
    8.             float[,] m_TileHeightMap = new float[tdata.heightmapWidth, tdata.heightmapHeight];
    9.             float elevationRange = MaxElevation - MinElevation;
    10.             float thx = tdata.heightmapWidth - 1;
    11.             float thy = tdata.heightmapHeight - 1;
    12.             var y_Terrain_Col_num = (mapSize_row_x);
    13.             var x_Terrain_row_num = (mapSize_col_y);
    14.             // heightmap rotation
    15.             int tw = tdata.heightmapWidth - 1;
    16.             int th = tdata.heightmapHeight - 1;
    17.             float wRatio = (y_Terrain_Col_num ) / (tw);
    18.             float hRatio = (x_Terrain_row_num ) / (th);
    19.             for (int y = 0; y < tw; y++)
    20.             {
    21.                 for (int x = 0; x < th; x++)
    22.                 {
    23.                     var elevation = (_floatheightData[(int)((y) * hRatio), (int)(x * wRatio)]);
    24.                     float v = ((elevation - MinElevation) / elevationRange);
    25.                     m_TileHeightMap[x, y] = v;
    26.                 }
    27.             }
    28.             return m_TileHeightMap;
    29.         }
    30.         else return new float[0, 0];
    31.     }
    / Im using terrain.SetNeighbors but it not work


    after excuting code i have this :
     

    Attached Files:

  8. amosvorn

    amosvorn

    Joined:
    Oct 31, 2018
    Posts:
    5
    i have same problem, clamp seems to be close to what im trying to do.
     
    UnityGISTech likes this.