first post on the forum. Have just started developing on Unity, and really enjoying it so far. But wondered if anyone could help me with something I’ve been scratching my head over so far…
I have a scene where the camera is slightly raised, so I guess you have a kind isometric view.
I want to move an object along x (have no problems with this), and also be able to move it towards and away from the camera, i.e. along the z-axis.
I have kind of accomplised this by using the mouse position of y, working out that half the screen is filled by the floor, and just doing some calculations as to a rough estimate of where on z corresponds to y.
This works after a fashion, but is a bit messy. It seems there should be a much better way to get depth from a button click somewhere on a plane/floor.
thanks for the reply. I had a look through the other thread, and looked at the ScreenPointToRay function, and I don’t understand how it captures the z-axis.
I do use screen to world point - and the object I move works fine along the x-axis. but because mouse position only returns an x and y, I have no idea how to get distance/depth.
The ScreenPointtoRay also seems to say that z is ignored.
You are never going to move the mouse along the Z axis. Mice don’t work that way.
What he was saying was that you could approximate the mouse’s position in the world by raycasting from where it was and using the point that it intersects.
Most games, like Black and White, use that technique while hiding the mouse cursor and generate a 3D cursor in the world where the raycast hit the ground.