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:
[33382-screenshot+2014-10-07+19.35.03.png|33382]
The tiles, if the player moves to the side and return to the first nine generated tiles.
[33383-screenshot+2014-10-07+19.36.55.png|33383]
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";
}
}