I am currently working on implementing offline routing in a 3D map within a ThreeJS scene. My goal is to allow the user to click on a point and have a cube navigate to that point. While the navigation functionality is working correctly, I am facing an issue where the clicked point is not accurate. The flat map I am using is a plane in XZ coordinates with the Y axis pointing up. Within the scene, I have Orbit Controls which modify the position argument of the camera when orbiting, leading to inaccurate raycasting with my current setup. I need to obtain the correct XZ coordinates regardless of the orbit state. While I have achieved accurate coordinates for traditional raycasting in 3D, this approach is not suitable for my needs. I have tried the basic method from the ThreeJS documentation for raycasting, followed the solution provided in this question, and attempted unprojecting the mouse click using Vector3.unproject()
without any success.
You can view an illustration of my issue in this jsfiddle, which also includes some important explanatory comments.