Detecting mouse position in 3d space.

alt text

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!

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.