If you think this tutorial is helpful and would like to thank me:
or via PayPal:
https://www.paypal.com/paypalme/kampertee
Problem.
As a novice game development, I used to get confused between difference coordinates system in game engine (local space, world space, viewport space and screen space). Why not united them in one coordinates system? After a long research in google, unity document and making several indie games, I write this tutorial to explain the difference between each coordinates system and some best real life use-case with each ones.
Definition of each coordinate system.
World Space: Unity uses left-hand Cartesian system to represent position and rotation for transform in scene. In this coordinate system, there is a origin point called “O” which is the intersect of three axis and have position (0,0,0) and rotation (0,0,0). All other points position can be obtained by draw a perpendicular line through its to each axis. We can say Transform position is measured by its relative with origin “O”.

Local Space: Transform local position is measured by relative with its parent instead of origin O. So we have:
localPosition=position – parentPosition;
Screen Space:
Screen Space is defined by pixels(2D Cartesian coordinate system). The bottom left of screen is (0,0) and the top-right is (screenWidth,screenHeight) so if we have a landscape 1920*1080 screen, the top-right will have position (1920,1080).
Viewport Space: It’s represent position in relative with current camera view and defined by a real value between 0f and 1f. The bottom-left is (0f,0f) and the top-right is (1f,1f).
Fantastic but how to use them.
World Space position and rotation: You can have transform position, rotation in world space by using transform.position and transform.rotation property. Another way is click to a gameobject with no parent(in this case world position= local position) in hierarchy and look at transform component in inspector view.

Local Space position and rotation: Transform local position, rotation can access via transform.localPosition and transform.localRotation respectively. Unity transform component (in inspector) display the local position, rotation and scale of a transform with its parent.
Screen Space position: You can get position of a transform in screen space by using
Camera.main.WorldToScreenPoint(transform.position);
Viewport Space position: Similar to screen space, you can get position in viewport space by using
Camera.main.WorldToViewportPoint(transform.position);
Useful use-case with difference coordinate system in Unity
Move transform by x along x axis, y along y axis and z along z axis (local space vs world space).
transform.Translate(0, 0, Time.deltaTime);// local space

Transform will move along z axis(blue axis) in local space.transform.Translate(0, 0, Time.deltaTime, Space.World); //world space

Transform will move along z axis(blue axis) in world space.
=> Sometimes, local space and world space is the same(simple game object with no child..)
Applies a rotation of zAngle degrees around the z axis, xAngle degrees around the x axis, and yAngle degrees around the y axis(local space vs world space).

// Rotate the object 45 degrees around its local X axis
transform.Rotate(45, 0, 0);
//rotate 45 degrees around the World's X axis
transform.Rotate(45, 0, 0, Space.World);

Note that the direction of X axis in each occasion(local and world space ) is different.
Some tips when manipulate transform position and rotation using Unity Transform tools:
+Try switch between global-local and center-pivot can help you manipulate transform more easily.
+It’s better to manipulate transform using transform tools in scene view than directly modify its values in inspector because of Gimbal Lock problem.
Convert screen position, view-port position to world position and vice versa.
Sometimes, you want to convert position from screen space or view-port space (such as mouse position in screen to world position) to other coordinates system or vice versa. Luckily, Unity provides all the necessary function above in Camera class. Here is a short sample code to convert mouse position to world position(we have to pass the z world unit from the camera).
Vector3 screenPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);//10 is the z-world unit from camera
//so worldPos.z=Camera.main.tranform.position.z+10
Vector3 worldPos=Camera.main.ScreenToWorldPoint(screenPos);
Debug.Log(screenPos + "_" + worldPos);
If you think this tutorial is helpful and would like to thank me:
or via PayPal:


[url=https://www.watermanrussia.ru/pens/expert/WT7F-BLK5C/]Чернила в картридже Waterman Blue MINI[/url] или [url=https://www.watermanrussia.ru/pens/exception/WT6F-GLD1G/]waterman ручки цены[/url]
https://www.watermanrussia.ru/pens/expert/WT7R-BLK4C/
LikeLike
Error 212 [url=https://try.alexa.com/marketing-stack/competitor-keyword-matrix]origin is unreachable[/url]
LikeLike