# Retrieving X , Y and Z coordinates of model

**URL:** <https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590>\
**Category:** Questions\
**Tags:** coordinate-system, geometry\
**Created:** [December 14, 2020, 7:13pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590 "2020-12-14T19:13:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibrahimunal](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ibrahimunal/32/15146_2.png) [@ibrahimunal](https://discourse.threejs.org/u/ibrahimunal)\
**Post date:** [December 14, 2020, 7:13pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/1 "2020-12-14T19:13:31Z")

</div>

Hi everyone!  
I’ve been trying to gauge the distance between two points. As I googled it first I come up with this link.  
[[https://threejs.org/docs/#api/en/core/Raycaster](https://threejs.org/docs/#api/en/core/Raycaster)]  
However, I can only get X and Y coordinates but I also need to get Z since I try to calculate distances between 2 points in 3d model

const raycaster = new THREE.Raycaster();  
const mouse = new THREE.Vector2();

function onMouseMove( event ) {

```
// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

```

}  
I tried to create a Vector3D object but still can’t manage to get the Z value since the event object does not have a function for getting the Z

I’d be so grateful if anyone could help me with the issue

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [December 14, 2020, 7:25pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/2 "2020-12-14T19:25:08Z")

</div>

> [@ibrahimunal](#):
>
> distance between two points

2 points in 3D space or on the screen? 🤔

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [December 14, 2020, 7:34pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/3 "2020-12-14T19:34:40Z")

</div>

@ibrahimunal  
Hi!  
Are you looking for something like this? [[SOLVED]Mesure distance between two points on a object by clicking](https://discourse.threejs.org/t/solved-mesure-distance-between-two-points-on-a-object-by-clicking/6082/10)

---

<div class="post-metadata">

**Author:** ![ibrahimunal](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ibrahimunal/32/15146_2.png) [@ibrahimunal](https://discourse.threejs.org/u/ibrahimunal)\
**Post date:** [December 14, 2020, 7:49pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/4 "2020-12-14T19:49:03Z")

</div>

in 3D space… I can only get X and Y coordinates but not Z

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [December 14, 2020, 8:03pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/5 "2020-12-14T20:03:06Z")

</div>

But distance is a number - not a vector - it doesn’t have x, y, or z. 🤔

See link @prisoner849 shared. To get distance between 2 points in 3D it’s usually enough to subtract these points:

```javascript
const positionA = obj.position;
const positionB = obj.position;
const difference = new Three.Vector3().subVectors(positionB, positionA);

const distanceTotal = difference.length();

const distanceXAxis = Math.abs(difference.x);
const distanceYAxis = Math.abs(difference.y);
const distanceZAxis = Math.abs(difference.z);

```

---

<div class="post-metadata">

**Author:** ![ibrahimunal](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ibrahimunal/32/15146_2.png) [@ibrahimunal](https://discourse.threejs.org/u/ibrahimunal)\
**Post date:** [December 14, 2020, 8:23pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/6 "2020-12-14T20:23:59Z")

</div>

This was exactly what I’ve been looking for . I was also thinkig to add a mesh at the endpoints of the line. This is a brilliant solution. I was thinking of getting to coordinates of 2 points and calculate it by myself but thats much better! Thanks a lot!

---

<div class="post-metadata">

**Author:** ![ibrahimunal](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ibrahimunal/32/15146_2.png) [@ibrahimunal](https://discourse.threejs.org/u/ibrahimunal)\
**Post date:** [December 14, 2020, 8:25pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/7 "2020-12-14T20:25:00Z")

</div>

@prisoner849 codepen solution helped me to get the solutions. Thanks btw

---

<div class="post-metadata">

**Author:** ![check](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@check](https://discourse.threejs.org/u/check)\
**Post date:** [June 19, 2025, 1:23pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/8 "2025-06-19T13:23:37Z")

</div>

yo anybody got anything on how to make a basic camera movement based on both the “Sprite” mesh item’s movement (which I also need help with making it move with WASD) _and_ the position of the mouse. Just like reply w/ instructions on how to make a locked mouse that can move around the camera. Basically I just need like a first person engine or smthn

---

<div class="post-metadata">

**Author:** ![manthrax](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/manthrax/32/2596_2.png) [@manthrax](https://discourse.threejs.org/u/manthrax)\
**Post date:** [June 19, 2025, 7:16pm UTC](https://discourse.threejs.org/t/retrieving-x-y-and-z-coordinates-of-model/21590/9 "2025-06-19T19:16:48Z")

</div>

There is also a handy method on vector:

`somePoint.distanceTo( anotherPoint )`

@check  
One easy way if you’re using orbitcontrols…

When you move the sprite like..  
`sprite.position.x += 1;`  
Also move the camera by the same amount: `camera.position.x += 1;`

and the controls.target  
`controls.target.x += 1;`

This way the camera will follow the sprite, the camera will stay pointing at the sprite… but you will still be able to rotate the camera.

There is also this example which is more complex but covers simple collision/wall sliding and FPS style movement:

> **[three.js examples](https://threejs.org/examples/?q=fps#games_fps)**
