- Home /
Detecting mouse position in 3d space.
I'm a bit of a beginner and I'm trying to figure out something that's been frustrating me. I'm trying to make Runescape like movement. Point and click. The technique I've decided on is that when the player clicks on the ground an object is created. That's what the MouseMove Object is that you see. The player will then move towards the mouse move object until his x and y coordinates match the MouseMove's coordinates. Then he will stop. The problem is the mouse position is obviously made up of 2d x and y coordinates and I can't figure out a method to convert them. Perhaps I don't even need to convert them? I don't know too much about it and I don't know if there is some other method I could use. I mainly use C#, but I will except JavaScript. If you post an example be sure to explain it as thoroughly as possible. Thanks!
Answer by Graham-Dunnett · Oct 14, 2011 at 09:07 PM
Fire a ray from the camera (Physics.Raycast) into the scene through the pixel where the click occurs. This will give you the world space position of where the ray hits an object. You now have a 3d position in your world space. Move your player towards this point.
Your answer
Follow this Question
Related Questions
Get mouse positon in world coordinates on a plane? 2 Answers
Having trouble getting Custom Editor to get a world point. 4 Answers
How to get mouse position in World Space when in Editor Mode 1 Answer
Event System value of mouse position is wrong. 0 Answers
Find Mouse co-ordinates on click in a 2d environment 5 Answers