I am creating voxel-based game (Minecraft etc.) and I was wondering how to rotate chunk parts that are more complex than simple squares, like the sides of a cube are.
For example, I created a staircase by manually constructing the mesh from code by giving the script the x,y,z coordinates of the virtual cube the staircase should appear in.
Now, how must I change the vertex coordinates of the staircase mesh so it gets rotated 90 degrees? Keep in mind that I can’t just rotate the whole gameobject because the stairs would be part of a chunk’s mesh.
Part of the code (creates vertices for one side of a very simple two-step staircase):
List<Vector3> vertices = new List<Vector3>();
int x = 4;
int y = 0;
int z = 3;
int angle = 0;//0 = 0 degrees, 1 = 90, and so on.
vertices.Add(new Vector3(x, y, z));
vertices.Add(new Vector3(x, y + 1, z));
vertices.Add(new Vector3(x + 0.5f, y + 1, z));
vertices.Add(new Vector3(x + 0.5f, y + 0.5f, z));
vertices.Add(new Vector3(x + 1, y + 0.5f, z));
vertices.Add(new Vector3(x + 1, y, z));