Ramaraunt1

terrain noise

Dec 27th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. void randomTerrain(Edit edit, Terrain terrain)
  2. {
  3. int xResolution = terrain.terrainData.heightmapWidth;
  4. int zResolution = terrain.terrainData.heightmapHeight;
  5. height = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight);
  6.  
  7. switch(edit)
  8. {
  9. case Edit.cosinoise:
  10. for (int z = 0; z < zResolution; z++)
  11. {
  12. for (int x = 0; x < xResolution; x++)
  13. {
  14. float xSin = Mathf.Cos(x);
  15. float zSin = -Mathf.Sin(z);
  16. height[x, z] = (xSin - zSin) / 100;
  17. }
  18. }
  19. break;
  20. case Edit.perlin:
  21. for (int z = 0; z < zResolution; z++)
  22. {
  23. for (int x = 0; x < xResolution; x++)
  24. {
  25. height[x,z] = Mathf.PerlinNoise(((float)x / (float)terrain.terrainData.heightmapWidth) * noisesize, ((float)z / (float)terrain.terrainData.heightmapHeight) * noisesize) / 10.0f;
  26. }
  27. }
  28. break;
  29. }
  30.  
  31. terrain.terrainData.SetHeights(0, 0, height);
  32. for (int z = 0; z < zResolution; z++)
  33. {
  34. for (int x = 0; x < xResolution; x++)
  35. {
  36. chunk1.setTile(x, z, new Tile((int)height[x, z], 0));
  37. }
  38. }
  39.  
  40. }
  41.  
  42. public enum Edit
  43. {
  44. perlin,
  45. cosinoise
  46. }
Advertisement
Add Comment
Please, Sign In to add comment