Why do scale and position not correspond?

I expand a plane programatically to 10,1, 10.

ground.transform.localScale = new Vector3(x_max, 1, z_max);

Then I programatically add a cube (wall) to position (0, 0, 10).

    // North wall.
    GameObject wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
        wall.name = "NorthWall";
        wall.transform.position = new Vector3(0, 0.5f, z_max);
        wall.transform.localScale = new Vector3(x_max * 2, 1, 0.1f);

        Material material = Resources.Load("Walls", typeof(Material)) as Material;
        Renderer mesh = wall.GetComponent<Renderer>();
        mesh.material = material;

I’m expecting the wall to be on the edge of the plane. However it is only about 1/5th the distance. I have to set the wall to position (0,0, 50) to be on the edge.


The plane primitive has a default dimension of 10x10 (not 1x1 which you are assuming, like other primitives). Thus you are scaling the plane to 100x100 (centered at origin, I presume). This would mean that it is 50 units in half-width and thus, the edge that you’re referring to would be located at (0,0,50).

So to fix your code, you could take into account the default size by using a scale factor of 1/10,

ground.transform.localScale = new Vector3(x_max / 10, 1, z_max / 10);