Precautions for coordinate transformation of Transform IN unity3D game development, unity3dtransform

Source: Internet
Author: User

Precautions for coordinate transformation of Transform IN unity3D game development, unity3dtransform

Transform is one of the core classes of unity. It indicates the translation, rotation, and scaling of objects.
Position and localPosition,
Transform is the world space and parent space respectively.
Note that the parent space is not its own space.
After you have noticed this, it will be much easier to change the space.


If you want to understand the transformation process of transform. position, you can test it as follows:

Java code
  1. // The parent space is transferred 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. // Convert world 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



However, if transform is directly used for transformation, the result will be incorrect]
Java code


  1. Debug. Log (transform. position );
  2. Debug. Log (transform. TransformPoint (transform. localPosition ));
  3. Debug. Log (transform. localToWorldMatrix. MultiplyPoint (transform. localPosition ));
Copy code



In this case, you should note that transform. localXXX represents the description in the parent space.
XXXPosition, EulerAngles, Scale)

If you want to convert the transformation information of one space into another space, you can do this:
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 depends on the actual situation]

Related Article

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.