- Home /
How to get real local position of objects from many levels?
I need to get relative position of objects in this hierarchy with respect to parent position and rotation. Subtraction works only if root object (MeshCenter) rotation in Z axis is static(setted to 0) In this case, root is set to 45 degrees. Transform.InversePoint give weird results, maybe I'm using it wrong? The red circuit is made from world positions.
for (int i = 0; i < verticesColliderList.Count; i++)
{
//GREEN COLLIDER
verticesColliderList[i] = new Vector2(ColTransformList[i].position.x - transform.position.x,
ColTransformList[i].position.y - transform.position.y);
}
for (int i = 0; i < verticesColliderList.Count - 1; i++)
{
// RED IS CORRECT
Debug.DrawLine(ColTransformList[i].position, ColTransformList[i + 1].position, Color.red);
//YELLOW WTF?
Debug.DrawLine(ColTransformList[i].InverseTransformPoint(transform.position),
ColTransformList[i + 1].InverseTransformPoint(transform.position), Color.yellow);
}
Answer by CDAXRC · Oct 29, 2018 at 10:53 AM
I found solution should be this transform.InverseTransformPoint(ColTransformList[i].position).x
Your answer
Follow this Question
Related Questions
Find Distance on Single, Relative Axis? 1 Answer
How do you move the camera relative to the direction it is currently facing? 1 Answer
Difference between transform.forward and transform.position.z? 1 Answer
Storing transforms from objects in Array 1 Answer
Trying to set up some GUI using planes and textures. Need help with dynamic changes. 0 Answers