Unity coordinate system

1. Left-handed coordinate system and right-handed coordinate system

Common 3D software uses the Cartesian coordinate system, which is the common xyz axis coordinate system. The Cartesian coordinate system can be a left-handed coordinate system or a right-handed coordinate system, as shown in the figure below678573c344804cfc972b6c07bb03eafe.png

 Both coordinate systems are mirror symmetric. However, Unity adopts the left-handed system, and the default direction of the xyz axis is exactly the same as the left-handed system in the figure, corresponding to right, up, and front.

Summarized as follows:

  • x: right, (1, 0, 0), red, Vector3.right
  • y: up, (0, 1, 0), green, Vector3.up
  • z: forward, (0, 0, 1), blue, Vector3.forward

2. World coordinate system and local coordinate system

The difference between the two is that the frame of reference is different, just like the relative position in high school physics.

The world coordinate system is confirmed by the coordinate system of the scene itself, and the local coordinate system is confirmed by the parent object of the object as the coordinate system. On a deeper level, the coordinate values ​​on the editor panel can all be understood as the values ​​of the local coordinate system. For the first-level object, its parent node is the scene itself, so its local coordinate system = world coordinate system

Here are some examples:

Vector3 worldpos=transform.position;//Get the world coordinates

Vector3 localPos=transform.localPosition;//Get local coordinates

 //rotate

Quaternion worldRotation=transform.rotation;

Quaternion localRotation=transform.localRotation;

 //Scaling in the local coordinate system of the parent object. There is no way to directly get the scaling of the world coordinates

Vector3 localScale=transform.localScale;

 

Guess you like

Origin blog.csdn.net/m0_63024355/article/details/130628909