transform is one of unity's core classes. Represents the translation, rotation, and scaling of objects . and position and localposition, respectively, the location of the transform is the world space, and the description of the parent space. attention isParent Space, not self-space. after noticing this, there is a lot of worry when it comes to changing space.
if you want to figure out the Transform.position transformation process, you can test this:
Java Code
- //parent space to the world.
- Debug.Log (transform.position);
- Debug.Log ( Transform.parent.TransformPoint (transform.localposition));
- Debug.Log ( Transform.parent.localToWorldMatrix.MultiplyPoint (transform.localposition));
Copy Code
Java Code
- //world transfer to parent space
- Debug.Log (transform.localposition);
- Debug.Log ( Transform.parent.InverseTransformPoint (transform.position));
- Debug.Log ( Transform.parent.worldToLocalMatrix.MultiplyPoint (transform.position));
Copy Code
But if you use transform directly to transform it, the result will be incorrect. "Dog Planing Learning net" Java Code
- Debug.Log (transform.position);
- Debug.Log (transform. Transformpoint (transform.localposition));
- Debug.Log (Transform.localToWorldMatrix.MultiplyPoint (transform.localposition));
Copy Code
at this point, it should be noted that TRANSFORM.LOCALXXX represents the description of the parent space. XXXposition,eulerangles,scale)
If you want to convert a space's transformation information near another space, you can: 1 The simplest way Java Code
- Transform.position = target.position;
- Transform.rotation = target.rotation;
- Transform.localscale = Target.lossyscale;
Copy Code
of course, it also needs to be subject to specific circumstances."Dog Planing Learning net" |
Unity3d game Development Transform coordinate transformation considerations