Baked mash is not readable

Hi

i have some script, which adjusts the terrain height, like on image

but works only if rotation 0 and scale 1

scale is not big problem i think :slight_smile:
but what about rotation? is that posible?

thanks

        for (var i = 0; i < vertices.Length; i++)
        {
            Debug.Log(vertices[i] + transform.position);

            Vector3 tempCoord = ((vertices[i] + transform.position) - terr.gameObject.transform.position);
            Vector3 coord;
            coord.x = tempCoord.x / terr.terrainData.size.x;
            coord.y = tempCoord.y / terr.terrainData.size.y;
            coord.z = tempCoord.z / terr.terrainData.size.z;

            posXInTerrain = (int)(coord.x * hmWidth);
            posYInTerrain = (int)(coord.z * hmHeight);
            int offset = size / 2;

            float[,] heights = terr.terrainData.GetHeights(posXInTerrain - offset, posYInTerrain - offset, size, size);

            for (int ii = 0; ii < size; ii++) {
                for (int j = 0; j < size; j++) {
                    heights[ii, j] = coord.y - 0.01f;
                }  
            }
               

            terr.terrainData.SetHeights(posXInTerrain - offset, posYInTerrain - offset, heights);
        }

You can use transform.InverseTransformPoint(someWorldPosition) to get the local (scaled, rotated, etc) equivalent of any world position.

1 Like

Thanks,
i try
transform.TransformPoint(meshVert)
and works