- Home /
vertices to world position
Seems im doing something wrong.
void Start () {
PaintableObjects = GameObject.FindGameObjectsWithTag("paintable");
Matrix4x4 localToWorld = transform.localToWorldMatrix;
foreach(GameObject go in PaintableObjects) {
Mesh mesh = go.GetComponent<MeshFilter>().sharedMesh;
testing = new Vector3[mesh.vertices.Length];
for (int test = 0; test < mesh.vertices.Length; test++) {
testing[test] = localToWorld.MultiplyPoint3x4(mesh.vertices[test]);
Debug.Log(testing[test] + " " + mesh.vertices[test]);
}
}
}
i have also tried transfrom.TransformPoint(); but i keep getting 0.5,-0.5,0.5 on both sides but that shouldn't happen the objects arent placed at 0.0.0 but at different locations. im using cubes to test so local world should be 0.5,-0.5,0.5 and with the x 2 the world space should be 2.5,-0.5,0.5 but instead im getting the normal value i get.
not sure what im doing wrong
Answer by Hatdatsat · Sep 19, 2018 at 11:25 AM
so i got it to work. i used this before:
transform.TransformPoint(mesh.vertices[vert]);
but you need to define the gameobject before transform so:
PaintableObjects[i].transform.TransformPoint(mesh.vertices[vert]);
I used a for loop instead of foreach that is why the [i] part. And the way i got my object was like this (not that its important how to get the object but i added it to explain the PaintableObjects[i] part)
PaintableObjects = GameObject.FindGameObjectsWithTag("paintable");
Your answer
Follow this Question
Related Questions
Move cube vertices up 2 units (world) whatever cube orientation 2 Answers
How to mark the vertices on a mesh and make the markers follow them as you apply transformations 0 Answers
How do I get rid of intersecting vertices between two gameobjects? 0 Answers