- Home /
How spaces works in unity?
There are viewport space, viewport point, screen space, screen point, world space what else? Ray?
I'm really having problems converting spaces cause I don't really understands them or I really don't know them. I have this problem converting an Input.mousePosition to screen space using WorldToScreenPoint but the vector it returns were outside from the camera(orthographic)/screen so I did try Camera functions and ScreenPointToRay(Vector3).origin do the work. So the question in my mind is: Which space does Input.mousePosition from? Does all instatiated gameObjects default space is world space? Why ScreenPointToRay did the work? Is screen point different from screen space? What is to Ray?
if you're curious how I ended up asking this check the script where I bumped into this problem.
Answer by Hellium · Apr 26, 2018 at 01:28 PM
Indeed, there are several spaces in the world of the 3D and computer graphics.
A space is defined by :
1. An origin = a reference point
2. Unit vectors, defining the "directions" of the possible dimensions
The main spaces are:
• World space :
Origin = (0, 0, 0)
Unit vectors = { (1, 0, 0), (0, 1, 0), (0, 0, 1) }
3D GameObjects without a parent are defined in the world space
• Local space :
Origin = position of the parent gameObject
Unit vectors = axes of the parent gameObject, according to its rotation
3D GameObjects with a parent are defined in the local space
• Screen space :
Origin = bottom-left corner of your screen (0, 0)
Unit vectors = { (1, 0), (0, 1) }, where one unit represent one pixel of your screen. The top-right corner of your screen has the following coordinates (Screen.width, Screen.height)
Input.mousePosition is defined in the Screen space
• Viewport space :
Origin = bottom-left corner of your screen (0, 0)
Unit vectors = { (1, 0), (0, 1) }. The top-right corner of your screen has the following coordinates (1, 1)
It's the normalized position of an object on the screen according to the screen dimensions
As indicated in the documentation
ScreenPointToRay
casts a ray starting on the near plane of the camera and going through position's (x,y) pixel coordinates on the screen.
Calling .origin
will return a world space point liying in the near plane of the camera.
Your answer
Follow this Question
Related Questions
Keeping the player inside the screen? 2 Answers
Make camera audio listener with FMODUnity 1 Answer
Camera Rendering Skewed Until Transform Adjusted 0 Answers
Problems implementing a 3rd person static camera 0 Answers
Crosshair Not Parallel To camera 1 Answer