- Home /
Procedural terrain bug?
My problem is that the first 9 tiles are generated wrong, the only difference in the function is that it instantiates the Plane instead of moving it.
First nine tiles, when the player is spawned:
The tiles, if the player moves to the side and return to the first nine generated tiles. So the two pictures of tiles above show the "Same" tiles, A.K.A. the tiles have the same world position.
var t : GameObject;
var tmp = GameObject.Find("Chunk "+fromnx+","+fromnz);
var ChunkPosX : float = terrainSize * nx;
var ChunkPosZ : float = terrainSize * nz;
if (fromnx == Mathf.Infinity && fromnz == Mathf.Infinity || tmp == null) {
t = GameObject.Instantiate(plane, Vector3(ChunkPosX, 0, ChunkPosZ), Quaternion.identity);
} else if (tmp != null) {
t = tmp;
t.transform.position = Vector3(ChunkPosX, 0, ChunkPosZ);
}
First 9 tiles:
function GenerateStandardTiles(pp : Vector3) {
//Player position divided by terrainSize(Width of terrain mesh)
var tx = Mathf.RoundToInt(pp.x / terrainSize);
var tz = Mathf.RoundToInt(pp.z / terrainSize);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx,tz);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx,tz + 1);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx + 1,tz);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx + 1,tz + 1);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx - 1,tz);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx - 1,tz + 1);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx - 1,tz - 1);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx + 1,tz - 1);
UpdateTile(Mathf.Infinity,Mathf.Infinity,tx,tz - 1);
}
Tiles generated after:
function GC(x : int, z : int, pp : Vector3) {
var tx = Mathf.RoundToInt(pp.x / terrainSize);
var tz = Mathf.RoundToInt(pp.z / terrainSize);
if (x == 1) {
UpdateTile(tx - 2, tz, tx + 1, tz);
UpdateTile(tx - 2, tz + 1, tx + 1, tz + 1);
UpdateTile(tx - 2, tz - 1, tx + 1, tz - 1);
status = "1x";
}
if (x == -1) {
UpdateTile(tx + 2, tz, tx - 1, tz);
UpdateTile(tx + 2, tz + 1, tx - 1, tz + 1);
UpdateTile(tx + 2, tz - 1, tx - 1, tz - 1);
status = "-1x";
}
if (z == 1) {
UpdateTile(tx, tz - 2, tx, tz + 1);
UpdateTile(tx + 1, tz - 2, tx + 1, tz + 1);
UpdateTile(tx - 1, tz - 2, tx - 1, tz + 1);
status = "1z";
}
if (z == -1) {
UpdateTile(tx, tz + 2, tx, tz - 1);
UpdateTile(tx + 1, tz + 2, tx + 1, tz - 1);
UpdateTile(tx - 1, tz + 2, tx - 1, tz - 1);
status = "-1z";
}
}
Answer by ExtremePowers · Nov 25, 2014 at 05:24 PM
Okay, I figured out the error, the Seed variable wasn't set when the first tiles were generated, so the seed was 0 for the first 9 tiles and the "real" seed for the rest, which made the "bug" occur.
Your answer
Follow this Question
Related Questions
A* Procedural Terrain 1 Answer
Procedural generation of dungeons with rooms made in the new tile map system? 0 Answers
Infinite Tiles but in both directions and despawn 0 Answers
Infinite Terrain Noise 1 Answer
Tile-based Generation Not Working? 1 Answer