Search Unity

Camera.ViewportToWorldPoint inconsistency

Discussion in 'Editor & General Support' started by xrm0, Jul 27, 2014.

  1. xrm0

    xrm0

    Joined:
    Feb 26, 2013
    Posts:
    86
    I'm doing a volleyball game (Tikiball WIP post) and found some strange behavior on Camera.ViewportToWorldPoint. I don't know whether it's my fault (most probably) or not.

    I'm using

    Code (CSharp):
    1. Camera.main.ViewportToWorldPoint (position);
    to translate a position in Viewport coordinates to a position in Worldpoint coordinates.

    If the project is exported to the web, the first time the game is loaded, for certain positions, ViewportToWorldPoint returns different values whether it's called in Start or in Awake. After refreshing the page, the values returned when called in both methods are the same (the expected outcome).

    I've made a small project to show this and is available at http://mulitasoft.com/games/tikiball/viewport-test
    Source code is at https://github.com/luisparravicini/test-ViewportToWorldPoint/
    I'm using Unity 4.5.1f3

    My results (in the first run) are:


    You'll notice point A have a negative value and ViewportToWorldPoint only mentions a range of [0,1]. So this might be a case of just me using an invalid value (althought it works fine in the editor). But point B is in the range specified in the docs and it also gives incorrect values.

    Do you get similar results as me? Any ideas why is this happening?
     
  2. xrm0

    xrm0

    Joined:
    Feb 26, 2013
    Posts:
    86
    Anyone has any idea on why this is happening?
    It seems a Unity bug to me