Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function UpdateTile(fromnx : int, fromnz : int, nx : int, nz : int) {
- var t : GameObject;
- var tmp = GameObject.Find("Chunk "+fromnx+","+fromnz);
- if (tmp != null) {
- t = tmp;
- } else {
- t = GameObject.Instantiate(plane, Vector3.zero, Quaternion.identity);
- }
- var Placed = 0;
- var ChunkPosX : float = terrainSize * nx;
- var ChunkPosZ : float = terrainSize * nz;
- var startPosX : int = (terrainSize - 1)*(nx-1);
- var startPosZ : int = (terrainSize - 1)*(nz-1);
- var mesh : Mesh = t.GetComponent(MeshFilter).mesh;
- var vertices : Vector3[] = mesh.vertices;
- var terrainHeight = (terrainSize / 5) * 3;
- for (var cur = 0; cur < vertices.Length; cur++) {
- var noise : float;
- var gain = StartGain;
- var WorldPnt = transform.TransformPoint(vertices[cur]);
- var Biome = GetBiome(WorldPnt.x,WorldPnt.z);
- for (var oc = 0; oc < Octaves; oc++) {
- noise += Mathf.PerlinNoise((Seed + WorldPnt.x)*gain/(terrainSize * scale), (Seed + WorldPnt.z)*gain/(terrainSize * scale)) / gain;
- gain *= 5;
- }
- var height = noise * terrainHeight;
- if (Biome == "Mountain") {
- noise += 0.2;
- }
- vertices[cur].y = noise * 150;
- }
- mesh.vertices = vertices;
- mesh.RecalculateNormals();
- mesh.RecalculateBounds();
- t.transform.position = new Vector3(ChunkPosX, 0,ChunkPosZ);
- t.name = "Chunk "+nx+","+nz;
- t.tag = "Chunk";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement