Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Why does Camera.main.ScreenToWorldPoint return only to the nearest tenths?

Discussion in 'Editor & General Support' started by CarterG81, Apr 28, 2014.

  1. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    Whenever I try to convert my mouse coordinate

    Code (csharp):
    1. Input.mousePosition
    into World Coordinates using

    Code (csharp):
    1. Camera.main.ScreenToWorldPoint(mousePos);
    It returns the World Position to the nearest tenths, such as 1.1, 1.2, 1.3, 1.4.

    However, all my units are in 100 Units per Pixel.

    This is horrible. I need it to tell me the World Coordinates to the hundredths. 1.10, 1.11, 1.12, 1.13.



    What am I doing wrong?

    Code (csharp):
    1.  
    2. Vector3 mousePOS = Input.mousePosition;
    3. Vector3 camera2worldPOS = Camera.main.ScreenToWorldPoint(mousePOS);
    4. Debug.Log ("Camera to World Position : " + camera2worldPOS);
    5.  
     
    mathiasvdbend likes this.
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    If you use the vector you're getting, you'll find that it contains the correct, detailed value. Vector3's default .ToString() function (which is implicitly used when you Debug.Log it) is where it's rounding to the nearest 0.1, not the vector itself. If you change your last line to this, you'll see it contains the real values:
    Code (csharp):
    1.  
    2. Debug.Log ("Camera to World Position : (" + camera2worldPOS.x + ", " + camera2worldPOS.y + ", "+camera2worldPOS.z+")");
    3.  
     
    mathiasvdbend likes this.
  3. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    thx

    $bc754f52a0f36317ddabfb626f84d559f1406eee36e63f0811a0233f3cd505e7.jpg
     
    mathiasvdbend likes this.