- Home /
Tile generation problem
I have a problem which isn't there in the editor but whenever I build, it is a problem. The problem is that my terrain generation doesn't generate the middle tile. (It is a 3x3 tile system, which creates a procedurally generated terrain based on the position of the player) The tile isn't there which is a problem because the player can then jump out of the world. I have checked that my tile function is called and that the end of the script is called.
EDIT:
//terrainSize = 500;
//terrainHeight = 225;
function UpdateTile(fromnx : int, fromnz : int, nx : int, nz : int) {
if (Network.isServer) {
Seed = PlayerPrefs.GetInt("Seed");
}
Random.seed = Seed;
var Chunk : Terrain;
var ChunkPosX : float = terrainSize * nx;
var ChunkPosZ : float = terrainSize * nz;
var tmp = GameObject.Find("Chunk "+fromnx+","+fromnz);
if (tmp) {
Destroy(tmp);
}
var td = new TerrainData();
td.heightmapResolution = terrainSize/2;
td.size = new Vector3(terrainSize, terrainHeight, terrainSize);
var tmp1 = Terrain.CreateTerrainGameObject(td);
tmp1.tag = "Chunk";
Chunk = tmp1.GetComponent(Terrain);
Chunk = tmp.GetComponent(Terrain);
var hw : float = Chunk.terrainData.heightmapWidth;
for (var child : Transform in Chunk.transform) {
if(child.name == "TreeMaster") {
GameObject.Destroy(child.gameObject);
Debug.Log("Destroying Treemaster ("+nx+","+nz+")");
}
}
var TreeMaster : GameObject = new GameObject();
TreeMaster.name = "TreeMaster";
TreeMaster.transform.parent = Chunk.transform;
Chunk.transform.position = Vector3(ChunkPosX, 0, ChunkPosZ);
Chunk.name = "Chunk "+nx+","+nz;
var perlin : PerlinNoise;
var heightmap = new float[hw,hw];
for(var x = 0; x < hw; x++) {
for(var z = 0; z < hw; z++) {
var worldPosX : float = (x+((hw-1)*(nx-1)))*(terrainSize/hw);
var worldPosZ : float = (z+((hw-1)*(nz-1)))*(terrainSize/hw);
if (perlin == null) {
perlin = new PerlinNoise(Seed);
}
var mountains : float = Mathf.Max(0f, (perlin.FractalNoise2D(worldPosX+250, worldPosZ+250, 7, mountainFrq, 0.5f))-0.1);
var plain : float = perlin.FractalNoise2D(worldPosX-250, worldPosZ-250, Octaves, groundFrq, 0.5f) + 0.5;
var height = (plain + mountains) * terrainHeight;
heightmap[z,x] = plain+mountains;
if (TakeItSlow) {
if (z % hw == 0 && x % 2 == 0) {
yield null;
}
}
}
}
Chunk.terrainData.SetHeights(0,0,heightmap);
pf++;
}
The seed, is the same through all the tiles, so that isn't the problem.
Post your tile generation script so others can check if anything's wrong with it. Also check the log file of your build if there have been any errors.
There is no errors in the output_log except a shader which is missing, but that shouldn't be the problem.
Answer by khos85 · Jan 14, 2015 at 10:46 PM
Could the tile be there but not in the correct/expected position? Maybe print out coords of tiles to a gui label to check this?
Or: Is your terrain using the missing shader somehow? Fix the shader issue, then test again, Or enclose all code in try catch, check the exception
The terrain isn't using the missing shader, it is a shader for some mesh grass I planned on using but never actually made. I will try the thing with the coordinates and return to you with the results :-)
Ok cool , but even if your terrain is not using the shader try to sort that shader error out so you have no errors in game, I suspect that would help. I've seen stuff like that happen in my games.
Okay, so I found out that that wasn't the problem: I printed their position and they are all at the right position. I have also fixed the shader problem but that didn't do anything aswell.
$$anonymous$$aybe the normals of the "missing" tile are flipped and so the tile's mesh only shows from the underside?
I have just tested if the tile is even there, its position gets printed but the tile isn't there at all in the end. I printed the number of tiles in the editor which gave me 9 and when compiled it gave me 8.
Your answer
Follow this Question
Related Questions
Tiling problem with Perlin generated terrain chunks 1 Answer
CoherentNoise still coherent through diferent terrains 0 Answers
How would one approach tile-by-tile terrain generation with Perlin Noise? 0 Answers
Dynamic Terrain Loading 4 Answers
[BEGINNER] Generating Terrain with Perlin noise flat and nothing happens ? 1 Answer