Advertisement
Guest User

Untitled

a guest
Sep 26th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. function UpdateTile(fromnx : int, fromnz : int, nx : int, nz : int) {
  2. var t : GameObject;
  3. var tmp = GameObject.Find("Chunk "+fromnx+","+fromnz);
  4. if (tmp != null) {
  5. t = tmp;
  6. } else {
  7. t = GameObject.Instantiate(plane, Vector3.zero, Quaternion.identity);
  8. }
  9.  
  10. var Placed = 0;
  11.  
  12. var ChunkPosX : float = terrainSize * nx;
  13. var ChunkPosZ : float = terrainSize * nz;
  14.  
  15. var startPosX : int = (terrainSize - 1)*(nx-1);
  16. var startPosZ : int = (terrainSize - 1)*(nz-1);
  17.  
  18. var mesh : Mesh = t.GetComponent(MeshFilter).mesh;
  19. var vertices : Vector3[] = mesh.vertices;
  20. var terrainHeight = (terrainSize / 5) * 3;
  21. for (var cur = 0; cur < vertices.Length; cur++) {
  22. var noise : float;
  23. var gain = StartGain;
  24. var WorldPnt = transform.TransformPoint(vertices[cur]);
  25. var Biome = GetBiome(WorldPnt.x,WorldPnt.z);
  26. for (var oc = 0; oc < Octaves; oc++) {
  27. noise += Mathf.PerlinNoise((Seed + WorldPnt.x)*gain/(terrainSize * scale), (Seed + WorldPnt.z)*gain/(terrainSize * scale)) / gain;
  28. gain *= 5;
  29. }
  30. var height = noise * terrainHeight;
  31. if (Biome == "Mountain") {
  32. noise += 0.2;
  33. }
  34. vertices[cur].y = noise * 150;
  35. }
  36.  
  37. mesh.vertices = vertices;
  38. mesh.RecalculateNormals();
  39. mesh.RecalculateBounds();
  40.  
  41. t.transform.position = new Vector3(ChunkPosX, 0,ChunkPosZ);
  42. t.name = "Chunk "+nx+","+nz;
  43. t.tag = "Chunk";
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement