ScreenToViewportPoint Bug?

I paste in the following lines from the example and attach this script to a game object.

function Update () {
		transform.position = Camera.main.ScreenToViewportPoint(Input.mousePosition);

But when the game runs my object to which this script is attached is way behind the camera near to 0,0,0. It also does not seem to move or rotate with the camera but moves slightly as I move the camera viewpoint. I would expect the object to be drawn at the mouse position no?

Any idea?


I think you are looking for the ScreenToWorldPoint function which gives coordinates in world space. The viewport function (as described in the reference) is basically a normalized version of the screen with (0,0) being the lower right and (1,1) being the upper left.