Moving an object to the location of a mouse click...

I've created a simple script that allows me to move the object the script is attached to to the coordinates of the mouse. However, when I began to click around, the object wouldn't go to the exact point of the mouse click but instead followed it at a distance. I'm kind of stumped on this problem, so I'll just provide the script and hope someone here knows a better way to do what I'm trying to do.

`function Update () { if (Input.GetButtonDown ("Fire1")) { transform.position = Vector3(Input.mousePosition.x, 0, Input.mousePosition.y); } }`

Use this:

plus this:

Screen position (i.e. Input.mousePosition) don't translate 1-to-1 to world coordinates (i.e. what transform.position is).

There are a lot of questions surrounding this here. Try this

The bottom corner of the screen is 0,0 and if you click in the corn the object would go to 0,0. If you click anywhere else it would go to some crazy number. I had the same problem still haven’t figured it out.