Failed to unproject vector using orthogonal camera

Hello,

I have an orthographic camera defined like this:

new three.OrthographicCamera(20 * aspectRatio / -2, 20 * aspectRatio / 2, 20 / 2, 20 / -2, -1000, 1000)

The canvas takes up the whole space. The camera position is (player.x - 3, 1 / 8 + 15, player.z + 15) and rotation ((-90 / 360) * Math.PI, (-15 / 360) * Math.PI, (-10 / 360) * Math.PI)

I want to interact with objects in the scene with the mouse, so I want to map 2d coordinates to (x, 1 / 8, z). 1 / 8 is top of the floor. All my Object3D have a parent which simulates a pivot in min point of the geometry, so by doing Math.floor(z) I will get the z-position of the clicked object

Using ray casting here doesn’t make sense, and is also expensive, since I don’t care about y-axis (which is facing up). I want to get (x, z) for the plane y = 1 / 8

I tried various answers and the latest code I have wrote down is:

let vec = new three.Vector3((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window.innerHeight) * 2 + 1, (camera.near + camera.far) / (camera.near - camera.far));
console.log(vec.unproject(camera));

With the help of GridHelper I click near the (0, 0, 0), but what I get in the console is no where near what it should be, I get x: -2.8929188820998046, y: 15.546389670485576, z: 15.493743978055074

I also tried an answer which said that by unprojecting I’ll get a ray which I have to extend until it hits y = 1 / 8, but the result was also way off (this time y was always 1 / 8, so I was extending fine)

bump

I’m still looking for a solution. At least give me some idea of how to debug the problem, or provide a snippet where the unprojecting works

Maybe the implementation of SelectionBox is helpful. The component is demonstrated in the following example: three.js webgl - box selection

Vector3.unproject() is used to update the internal frustum which is part of the object selection process. Check out the code of updateFrustum().