Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

ScreenToWorld.ScreenSpaceToWorldSpace - how to use it?

Discussion in 'Project Tiny' started by Sarkahn, Nov 27, 2020.

  1. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    Hello, I'm trying to set a position to a corner of the camera's viewport. According to the source file the first parameter is in pixels:
    Code (CSharp):
    1.         // screenPos is in pixels. Note that this is pixels, not points. So for platforms where pixels != points, this need to be adjusted first.
    2.         // depth is normalized -1..1, where -1 is near and 1 far
    3.         public float3 ScreenSpaceToWorldSpace(float2 screenPos, float normalizedZ, ScreenToWorldId id)
    I was expecting that if I pass (0,0) to this function it would return a world point at the bottom left corner of the camera's viewport, and passing the size of the viewport in pixels would give you the top right, but that doesn't seem to be the case.

    Code (CSharp):
    1. // Returns (-1,-1), regardless of camera position          
    2. var p = s2w.ScreenSpaceToWorldSpace(new float2(0,0), 10, ScreenToWorldId.MainCamera);
    How can I convert from a camera/viewport position to world space?
     
  2. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319