public float GenerateXZ(float x, float z, int seed, float scale, ChunkGenVariables vars) { float outValue = 0; for (int i = 0; i < vars.complexity; i++) { float seedModX = seed * (24 * i); float seedModY = seed * (43 * i); float value = Mathf.PerlinNoise((x + seedModX) * scale * 0.031f, (z + seedModY) * scale * 0.031f); outValue += value; } outValue /= vars.complexity; return(outValue); }
public void GenerateSingleChunk(int seed, float noiseScale, int maxHeight, Vector2 startPos, Vector2 endPos, ChunkGenVariables vars) { _blockManager.GenerateWorld(seed, noiseScale, maxHeight, startPos, endPos, vars); CreateWorld(_blockManager); }
public void Generate(int seed, float noiseScale, int maxHeight, int chunkSize, int chunks, ChunkGenVariables vars) { foreach (Transform child in transform) { Destroy(child.gameObject); } if (seed == 0) { seed = Random.Range(-100000, 100000); } for (int x = 0; x < chunks; x++) { int genPosX = chunkSize * x; for (int z = 0; z < chunks; z++) { int genPosZ = chunkSize * z; GenerateSingleChunk(seed, noiseScale, maxHeight, new Vector2(genPosX, genPosZ), new Vector2(genPosX + chunkSize, genPosZ + chunkSize), vars); } } }
public void GenerateWorld(int seed, float scale, int maxHeight, Vector2 startPos, Vector2 endPos, ChunkGenVariables vars) { startChunkPos = startPos; endChunkPos = endPos; if (seed == 0) { seed = 1; } world = new List <Block>(); float startX = (int)Math.Min(startPos.x, endPos.x); float endX = (int)Math.Max(startPos.x, endPos.x); float startZ = (int)Math.Min(startPos.y, endPos.y); float endZ = (int)Math.Max(startPos.y, endPos.y); for (float x = startX; x < endX; x++) { for (float z = startZ; z < endZ; z++) { //float seedModX = seed * 24; //float seedModY = seed * 43; float height = GenerateXZ(x, z, seed, scale, vars);//Mathf.PerlinNoise((x + seedModX) * scale * 0.031f, (z + seedModY) * scale * 0.031f); //AddBlock(new Block(new BlockVec((int)x, (int)(height * maxHeight), (int)z)), false); if (height >= 0) { PlaceBlocks(new Block(new BlockVec((int)x, vars.bottom - 1, (int)z)), new BlockVec((int)x + 1, (int)(height * maxHeight) + vars.bottom + vars.minHeight, (int)z + 1), false); } } } }