- Home /
Question by
Reeceg · May 06, 2015 at 05:09 AM ·
c#transformworldspacelocalspace
transform.position is giving me local space
This is my code to crate a quad but as the title says the quad is crated in local space and not world.
Mesh CrateMeshChunk()
{
V1 = Me.transform.position;
V2 = NeighbourTop.transform.position;
V3 = NeighbourLeft.transform.position;
V4 = NeighbourLeft.GetComponent<Neighbour>().NeighbourTop.transform.position;
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[]
{
V1,V2,V3,V4,
};
Vector2[] uv = new Vector2[]
{
UV1,UV2,UV3,UV4,
};
int[] triangles = new int[]
{
0, 1, 2,
2, 1, 3,
};
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
return mesh;
}
Comment
No, Transform.position is world space. In order to get local position (relative to a parent), you need to use Transform.localPosition.
The mesh.vertices are in local space relative to its attached gameObject, maybe you should transform the vertex position from world to local:
V1 = quadTransform.InverseTransformPoint($$anonymous$$e.transform.position);
V2 = quadTransform.InverseTransformPoint(NeighbourTop.transform.position);
V3 = quadTransform.InverseTransformPoint(NeighbourLeft.transform.position);
V4 = quadTransform.InverseTransformPoint(NeighbourLeft.GetComponent<Neighbour>().NeighbourTop.transform.position);
Best Answer
Answer by Reeceg · May 06, 2015 at 09:12 AM
The mesh.vertices are in local space relative to its attached gameObject, maybe you should transform the vertex position from world to local:
V1 = quadTransform.InverseTransformPoint(Me.transform.position);
V2 = quadTransform.InverseTransformPoint(NeighbourTop.transform.position);
V3 = quadTransform.InverseTransformPoint(NeighbourLeft.transform.position);
V4 = quadTransform.InverseTransformPoint(NeighbourLeft.GetComponent<Neighbour>().NeighbourTop.transform.position);
Yword