# three js Get position in space of 2 objects

0 favourites
• 3 posts
From the Asset Store
A slots game template designed to be skin-able for mobile
• I have two squares in space which are something like front and back wall of cube

one vith vertices

x=-2, y=-1138, z=-2

x=-2, y=-1134, z=-2

x=2, y=-1138, z=-2

x=2, y=-1134, z=-2

second

x=-2, y=1134, z=2

x=-2, y=1138, z=2

x=2, y=1134, z=2

x=2, y=1138, z=2

when I calculate distanceTo from camera like this

var point1 = this.camera.matrixWorld.getPosition().clone();

var point2 = this.mesh.cubePlane3.children[0].matrixWorld.getPosition().clone();

var distance = point1.distanceTo( point2 );

I have always the same distance for both 20,09. These squres are rotated in space, so only rotation is changed and I would need somehow find out which wall is closer to camera to be able to do something that in cube 3 walls closer to camera are not displayed and next 3 walls are displayed.

And obviously I do not understand math behind this, for example why walls which are next to each other one have positive coordinates for y and next negative + why distance is the same value, when one is closer on z axis than second. Can you pls someone help me how I can get closer walls? Thank you

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I think you're on the wrong forum. This forum is not for general purpose javascript, but for construct 2, which does not have three.js integrated.

• you better ask question in stack overflow

• 3 posts