Unity3d game Development Transform coordinate transformation considerations

Source: Internet
Author: User

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
    1. //parent space to the world.   
    2.     Debug.Log (transform.position);   
    3.     Debug.Log ( Transform.parent.TransformPoint (transform.localposition));   
    4.     Debug.Log ( Transform.parent.localToWorldMatrix.MultiplyPoint (transform.localposition));   
Copy Code


Java Code


    1. //world transfer to parent space   
    2.     Debug.Log (transform.localposition);   
    3.     Debug.Log ( Transform.parent.InverseTransformPoint (transform.position));   
    4.     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


    1. Debug.Log (transform.position);
    2. Debug.Log (transform. Transformpoint (transform.localposition));
    3. 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


    1. Transform.position = target.position;
    2. Transform.rotation = target.rotation;
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.