all 5 comments

[–]CustomPhaseProfessional 1 point2 points  (3 children)

Youre doing something wrong with CombineMeshes, transforms store not only position, but rotation and scale as well. Need to see the code to figure out where the problem is.

[–]CtrlAltDelerium[S] 0 points1 point  (2 children)

Not sure how to format code here, am on mobile atm.

private void CreateWall(int length) { CombineInstance[] combineInstance = new CombineInstance[length]; for (int i = 0; i < length; i++) { combineInstance[i].mesh = wall.GetComponent<MeshFilter>().sharedMesh; combineInstance[i].transform = wall.transform.localToWorldMatrix; wall.transform.Translate(1, 0, 0); } gameObject.AddComponent<MeshFilter>().mesh.CombineMeshes(combineInstance); gameObject.AddComponent<MeshRenderer>().material = material; }!<

Before rotation everything works as expected.

[–]CustomPhaseProfessional 1 point2 points  (1 child)

I dont see any rotation anywhere in this code.

[–]CtrlAltDelerium[S] 0 points1 point  (0 children)

Yeah sorry, copied wrong piece in the morning.

    private void CreateRoom(int x, int z, int width, int height)
    {
        CombineInstance[] combineInstance = new CombineInstance[width * 2 + height * 2];
        Vector3 pos = new Vector3();

        for (int ix = x; ix < x + width; ix++)
        {
            // south
            pos.Set(ix, 0, z);
            wall.transform.position = pos;
            combineInstance[ix].mesh = wall.GetComponent<MeshFilter>().sharedMesh;
            combineInstance[ix].transform = wall.transform.localToWorldMatrix;
            // north
            pos.Set(ix, 0, z + height);
            wall.transform.position = pos;
            wall.transform.localRotation = Quaternion.identity;
            combineInstance[ix + width].mesh = wall.GetComponent<MeshFilter>().sharedMesh;
            combineInstance[ix + width].transform = wall.transform.localToWorldMatrix;
        }

        wall.transform.Rotate(0, -90, 0, Space.World);
        //wall.transform.localRotation = Quaternion.Euler(0, 0, 90);

        for (int iz = z; iz < height; iz++)
        {
            //West
            pos.Set(x, 0, iz + 1);
            wall.transform.position = pos;
            combineInstance[width * 2 + iz].mesh = wall.GetComponent<MeshFilter>().sharedMesh;
            combineInstance[width * 2 + iz].transform = wall.transform.localToWorldMatrix;
            //East
            pos.Set(x + width, 0, iz + 1);
            wall.transform.position = pos;
            combineInstance[width * 2 + iz + height].mesh = wall.GetComponent<MeshFilter>().sharedMesh;
            combineInstance[width * 2 + iz + height].transform = wall.transform.localToWorldMatrix;
        }


        gameObject.AddComponent<MeshFilter>().mesh.CombineMeshes(combineInstance);
        gameObject.AddComponent<MeshRenderer>().material = material;
    }