- Home /
Mouse Click To World Pos
I have a plane with a grid on it, and when I click it I need to know where the mouse clicked on it in world coordinates. I'm using JavaScript and Unity Free.
Answer by roojerry · Aug 27, 2013 at 07:01 PM
Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousPosition.y, distance));
This will transform the mouse position in screen coordinates to a world position a "distance" away from the camera
Distance is how far from the camera you want your world point calculated. Distance of 0 would be at the camera. Check the documentation for more info and an example
Answer by yoyo · Aug 27, 2013 at 06:48 PM
http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenToWorldPoint.html
(This question has been asked and answered several times before.)
I need to know the mouse pos in the world, not the camera pos.
Please click the link I provided, read the documentation, and learn how to use that method to answer your question. Here's another hint. :-)
Your answer
Follow this Question
Related Questions
trying to move an object with the mouse 1 Answer
How to detect double and single clicks using javascript? 1 Answer
Invert mouse control 2 Answers
Move at mouse click 0 Answers