# Tilemap mesh issue with z, -z axis

I don't understand why the created mesh is upside down if z ( z*tileSize ) is positive, the mesh is then rendered with the texture looking down. With "-z", the mesh texture is looking up correctly, but it then starts at 0,0,0 and follows his path to the negative values, which I don't want. (I would like the mesh to create tiles in the X/Z axis, not in the X/-Z axis).

Would you know how to fix this? Here is the method to create the mesh : (if I switch the normals to -Vector3.up, the plane texture is still looking down, and it becomes black.)

public void BuildMesh() {
int numTiles = size_x * size_z;
int numTris = numTiles * 2;

int vsize_x = size_x + 1;
int vsize_z = size_z + 1;
int numVerts = vsize_x * vsize_z;

// Generate the mesh data
Vector3[] vertices = new Vector3[ numVerts ];
Vector3[] normals = new Vector3[numVerts];
Vector2[] uv = new Vector2[numVerts];

int[] triangles = new int[ numTris * 3 ];

int x, z;
for(z=0; z < vsize_z; z++) {
for(x=0; x < vsize_x; x++) {
//HERE
vertices[ z * vsize_x + x ] = new Vector3( x*tileSize, 0, -z*tileSize );
normals[ z * vsize_x + x ] = Vector3.up;
uv[ z * vsize_x + x ] = new Vector2( (float)x / size_x, 1f - (float)z / size_z );
}
}

for(z=0; z < size_z; z++) {
for(x=0; x < size_x; x++) {
int squareIndex = z * size_x + x;
int triOffset = squareIndex * 6;
triangles[triOffset + 0] = z * vsize_x + x +           0;
triangles[triOffset + 1] = z * vsize_x + x + vsize_x + 1;
triangles[triOffset + 2] = z * vsize_x + x + vsize_x + 0;

triangles[triOffset + 3] = z * vsize_x + x +           0;
triangles[triOffset + 4] = z * vsize_x + x +           1;
triangles[triOffset + 5] = z * vsize_x + x + vsize_x + 1;
}
}


Thanks

• It seems like you started this question in the middle. What mesh is upside down? Commented Dec 2, 2013 at 15:08
• The mesh built with BuildMesh is a plane with a created texture. When z is positive, the texture is facing down, so it is visible if the camera is below the mesh. If z is negative, it works fine, but then the mesh is using the X/-Z axis.
– Paul
Commented Dec 2, 2013 at 15:31