I was previously using a 2D screen and PerspectiveCamera. Now I changed it to OrthographicCamera to achieve an isometric view.
I want to find the world coordinates from the mouse position. Previously, I was using these code pieces: point - Mouse / Canvas X, Y to Three.js World X, Y, Z - Stack Overflow
Now since I changed my Camera to Orthographic one, now I use this code to find world coordinates from mouse click:
let vector = new THREE.Vector3();
vector.set(
(event.clientX / window.innerWidth) * 2 - 1,
- (event.clientY / window.innerHeight) * 2 + 1,
0
);
vector.unproject(camera);
This is mostly working for 2D world but when I change my camera’s position to achieve an isometric, 3d-ish view like below code, it’s not working:
controls.setLookAt(x, y - 500, z, x, y, 0);
I use the camera-controls library (GitHub - yomotsu/camera-controls: A camera control for three.js, similar to THREE.OrbitControls yet supports smooth transitions and more features.)
With the above code I can achieve an isometric view with setting the camera’s y position like y - 500
. But when I do that my code for finding the world coordinates messed up.
I tried to reflect the camera’s position (minus 500 offset) to that vector calculation (by increasing the y coordinate of the vector) but it’s not working since the difference is not always the same in an isometric view. How can I keep the isometric view and also find the world position from mouse click.