- Home /
Help with vertex position of parent object
I have two objects. One of them is parent, another one is its child. I want to get vertex position of parent object. I use the following script, which is assigned to child object, to get the position of parent first vertex in axis X.
Vector3[] vertices = transform.parent.GetComponent<MeshFilter>().mesh.vertices;
var gPos = transform.TransformPoint(vertices[0]);
print("Parent vertex at " + gPos.x);
Another script is assigned to parent and performs the same function
Vector3[] vertices = GetComponent<MeshFilter>().mesh.vertices;
var gPos = transform.TransformPoint(vertices[0]);
print("Parent vertex at " + gPos.x);
But issue is that i have different numbers. For example, first script shows -5, second one -3. I know that this is somehow related to the position of child object relative to its parent, because the chilld object location in axis X is 2. It pluses this number and i get those results.
Can somebody help me to understand why i get different positions. Thank you.
Answer by gordiri · Jan 24, 2018 at 05:07 PM
Look at your second row in scripts. In first script you transform point relative to pchild, in second relative to parent object. Thats the problem
Thank you. That was the problem. Now everything works fine.
Your answer
![](https://koobas.hobune.stream/wayback/20220612151216im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I instantiate two prefabs at different times and positions ? 1 Answer
Positions mess up when built 1 Answer
Transform Cross for Map Creator in game 0 Answers
Positions in scene editor not same as in-game 1 Answer
How to find what positional axis an object's green axis corresponds to? 2 Answers