• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Rikimaru · May 24, 2012 at 10:03 AM · worldspacelocalspace

About World space and Local space

when I use several sample codes, I usually meet those ScreenToWorldPoint, WorldToScreenPoint, InverseTransformDirection etc...

these used many areas : camera or mouse move code. and descriptions of these are convert space : from screen to local, from local to world or from world to local etc...

But I don't know that difference and why I should use it.

plz teach me.. T.T

Comment
flamy
omrip32
tribski
godfreyidk
enoy
felixmann

People who like this

6 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

  • Sort: 
avatar image
Best Answer

Answer by flamy · May 24, 2012 at 10:26 AM

Unity uses 3 different co-ordinate systems, World point system, Screen point system and view-port point system. These functions are used to find where the particular point will be in another point system.

To be clear, when you are giving a mouse input or touch input, it will be in screen point system. which has only x and y. to use this inside the game and set it to a particular object ( snap an object to mouse) takes certain work, you have to consider camera position, rotation, object depth and stuffs, ScreenToWorldPoint function makes the developer's work simple. it converts the point to world co-ordinate jus by taking mouse position and z depth.

view port is the space to which the camera renders. sometime you can get the area occupied by an object on the view port and used it like a button(just an example), in case of orthographic it will be easy. In this care you have to convert the world point to and from viewport point. so you need to use WorldToViewportPoint and it alias function.

the image i have attached would show why the conversion is must link text


Untitled drawing.pdf (20.9 kB)
Comment
hardRock
robertbu
Bunny83
Anlasa
ErnestoBananez
Juyong Woo
McBritish
SanSolo
Nickolauson
bkmagnetron
chelder
omrip32
thedarcsage
shohan4556
enoy
And 4 more...

People who like this

19 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image janoonk · Feb 19, 2013 at 08:20 PM 0
Share

Your drawing about Screenspace is wrong: bottom-left is (0,0). Just attach this code to a GameObject:

 using UnityEngine;
 using System.Collections;
 
 public class example : MonoBehaviour {
     void OnDrawGizmos() {
         Vector3 p = Camera.main.camera.ScreenToWorldPoint(new Vector3(0,0, Camera.main.camera.nearClipPlane));
         Gizmos.color = Color.yellow;
         Gizmos.DrawSphere(p, 0.1F);
     }
 }

alt text

spaces.jpg (37.4 kB)
avatar image

Answer by Wolfram · May 24, 2012 at 10:23 AM

Local vs. world space: http://answers.unity3d.com/questions/31169/explanation-local-vs-global-space.html

Screen vs. world space: here is an example: http://answers.unity3d.com/questions/14404/create-an-object-in-screen-space-coordinate.html

A really short overview:

  • World Space: the absolute XYZ coordinates of all objects

  • Local Space: relative coordinates, in relation to a reference object. For example within an object hierarchy, the Transforms of all children are local to their parent

  • Screen space: an essentially twodimensional space, used to place objects directly at certain absolute pixel positions on your screen

The methods you found are used to convert from one coordinate representation to another. For example, convert the x/y position of a mouse to a direction from the camera position into the world space of the scene.

Also, google a bit for these keywords, you will find plenty of tutorials and explanations of each coordinate space.

Comment
Bunny83

People who like this

1 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TokyoDan · Apr 10, 2013 at 06:04 AM 0
Share

The third bulleted point really confuses me as I read that the values of screen space range from -1 to 1. If that is true then how can it be used "to place objects directly at certain absolute pixel positions on your screen."?

avatar image Wolfram · Apr 10, 2013 at 10:13 AM 0
Share

@tokyodan: what you mean is Viewport Space, see @janoonk's picture above. Screenspace uses pixels: http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenToWorldPoint.html

avatar image TokyoDan · Apr 10, 2013 at 11:52 AM 0
Share

Sorry. That's right. I was confusing it with viewport.

avatar image

Answer by lilinjie_ · Sep 09, 2017 at 03:15 PM

 // You can try this in Unity to see the value of Screen Space point, View Space point
 // and World Sapce point.
 
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Test : MonoBehaviour
 {
     /*
      * A screen space point is defined in pixels. The bottom-left of the screen
      * is ( 0, 0 ); the right-top is ( pixelWidth, pixelHeight ). The z position
      * is in world units from the camera.
      * 
      * A viewport space point is normalized and relative to the Camera. The 
      * bottom-left of the Camera is ( 0, 0 ); the top-right is ( 1, 1 ). The z 
      * position is in world unity from the camera.
      * 
      * A world space point is defined in global coordinates(for example, 
      * Transform.position).
      * 
      * There are a visual show:
      * http://blog.projectmw.net/unitys-screen-point-viewport-point-and-world-point
      * 
      * Local Space VS World Space:
      * http://answers.unity3d.com/questions/31169/explanation-local-vs-global-space.html
      * 
      * Reference:
      * https://docs.unity3d.com/ScriptReference/Camera.html
      */
 
 
     void OnGUI()
     {
         Camera c = Camera.main;
         Event e = Event.current;
 
         Vector2 mousePos = new Vector2();
 
         // Get mouse position in Screen space point
         mousePos.x = e.mousePosition.x;
         // The e.mousePosition.y is reverse
         mousePos.y = c.pixelHeight - e.mousePosition.y;
 
         Vector3 screenPoint = new Vector3( mousePos.x, mousePos.y, c.nearClipPlane );
         // View space point's z is the c.nearClipPlane
         Vector3 viewPoint = c.ScreenToViewportPoint( screenPoint );
         // When the Camera's rotation equal Vector3.zero, the World Space point's 
         // z is the c.transform.z + c.nearClipPlane
         Vector3 worldPoint = c.ScreenToWorldPoint( screenPoint );
 
         GUILayout.BeginArea( new Rect( 20, 20, 300, 120 ) );
         GUILayout.Label( "Screen pixels: " + c.pixelWidth + ":" + c.pixelHeight );
         GUILayout.Label( "Screen position: " + mousePos.ToString( "F2" ) );
         GUILayout.Label( "Viewpoint position: " + viewPoint.ToString( "F2" ) );
         GUILayout.Label( "World position: " + worldPoint.ToString( "F2" ) );
         GUILayout.EndArea();
     }
 }
Comment
SlimeProphet

People who like this

1 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Danze3 · May 24, 2012 at 11:02 AM

World Space is the XYZ on the main World, which you see in the upper right corner of the screen.

Local Space refers to the Objects XYZ which is entirely different with the World XYZ

if you use Rigidbody's XYZ, it will use Local Space. If you use the Transform, it will use the World Space.

If still unsure, I can redirect you to the Video Explanation.

Comment

People who like this

0 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · May 24, 2012 at 11:37 AM 0
Share

Uhm, the Transdorm inspector shows always the local space coordinates (.localPosition), even when you switch the local / global. A Rigidbody on the other hand is always simulated in worldspace.

avatar image jister · Feb 27, 2013 at 08:05 AM 0
Share

Which one is correct? Rigidbody local or world space?

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

rigidbody.MoveRotation neither world space or local? How does it work? 1 Answer

What is the difference between TransformDirection, TransformVector and TransformPoint since they all accept and return a Vector3 value. 1 Answer

Applying Constant Force to Object A using Object B's Vectors. 0 Answers

Box Collider Vertexes in World Space 3 Answers

Raycasting, How to draw a line to the position of the rays end when nothing is hit 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges