Guest User

PopulateTerrainMap

a guest
Jul 13th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. void PopulateTerrainMap() { //Tells what height each corner should be
  2.  
  3.             //Corners are shared, but still need to be one larger so we can hold all of the corner data
  4.             for (int z = 0; z < TerrainData.Width + 1; z++)
  5.             {
  6.                 for (int y = 0; y < TerrainData.Height + 1; y++)
  7.                 {
  8.                     for (int x = 0; x < TerrainData.Width + 1; x++)
  9.                     {
  10.  
  11.                         // Get a terrain height using regular old Perlin noise.
  12.                         float thisHeight = TerrainData.GetTerrainHeight(x + chunkPos.x, z + chunkPos.z); //We use + chunkPosition because we dont want every chun to look the same
  13.                         float diggedHeight = (float)y - thisHeight;
  14.  
  15.                         ChangeVoxel();
  16.  
  17.                         if(y < thisHeight - 1) {
  18.                             World.Instance.blockID = 3; //Dirt
  19.                         }
  20.  
  21.                         blockID = World.Instance.blocks.blockTypes[World.Instance.blockID].blockID;
  22.                         blockName = World.Instance.blocks.blockTypes[World.Instance.blockID].Name;
  23.                        
  24.                        
  25.                         // Set the value of this point in the terrainMap array and stores the data so we dont regenerate the data everyytime we modify the terrain.
  26.                         terrainMap[x, y, z] = new TerrainPoint(diggedHeight, blockID, blockName); //Get the dst to surfac value and returns a random texture ID
  27.                     }
  28.                 }
  29.             }
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment