# Create a directional vector with 2 position vectors

**URL:** <https://forum.babylonjs.com/t/create-a-directional-vector-with-2-position-vectors/3685>\
**Category:** Questions\
**Created:** [June 4, 2019, 9:10am UTC](https://forum.babylonjs.com/t/create-a-directional-vector-with-2-position-vectors/3685 "2019-06-04T09:10:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jez/32/2219_2.png) [@Jez](https://forum.babylonjs.com/u/Jez)\
**Post date:** [June 4, 2019, 9:10am UTC](https://forum.babylonjs.com/t/create-a-directional-vector-with-2-position-vectors/3685/1 "2019-06-04T09:10:31Z")

</div>

Hello,

I was wondering if it exists a function in Babylon to create a new Vector3 with two position vectors as arguments.

For example if I click somewhere in the world I want to get back the position of my click and with the position of my active camera create a new directional Vector3 (from the camera position to the click position, get with pickedPoint) to use with cameraDirection.

Best regards,  
Jez

---

<div class="post-metadata">

**Author:** ![Jez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jez/32/2219_2.png) [@Jez](https://forum.babylonjs.com/u/Jez)\
**Post date:** [June 4, 2019, 10:11am UTC](https://forum.babylonjs.com/t/create-a-directional-vector-with-2-position-vectors/3685/2 "2019-06-04T10:11:55Z")

</div>

I find the solution :

window.addEventListener(“click”, function () {  
// We try to pick an object  
var pickResult = scene.pick(scene.pointerX, scene.pointerY);  
console.log(pickResult);  
//let vec3 = camera.getTarget().subtract(camera.position)  
let vec3 = pickResult.pickedPoint.subtract(camera.position).normalize();  
camera.cameraDirection = new BABYLON.Vector3(vec3.x, 0, vec3.z); // I want to avoid to move the Y axis

```
            }); 

```

So what I needed was the normalize but I don’t understand what it’s doing.

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [June 4, 2019, 10:35am UTC](https://forum.babylonjs.com/t/create-a-directional-vector-with-2-position-vectors/3685/3 "2019-06-04T10:35:27Z")

</div>

> [@Jez](#):
>
> So what I needed was the normalize but I don’t understand what it’s doing.

It is creating a unit vector from the vector, ie one in the same direction with magnitude 1.

a.normalize() = a/||a||

a = (2, 3, 6)

||a||2 = 22 + 32 + 62 = 4 + 9 + 36 = 49  
||a|| = 7

(2, 3, 6).normalize() = (2/7, 3/7, 6/7)

---

<div class="post-metadata">

**Author:** ![Jez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jez/32/2219_2.png) [@Jez](https://forum.babylonjs.com/u/Jez)\
**Post date:** [June 5, 2019, 1:21am UTC](https://forum.babylonjs.com/t/create-a-directional-vector-with-2-position-vectors/3685/4 "2019-06-05T01:21:41Z")

</div>

Hello JohnK,

I got it! thank you very much for your help !!!

So finally it doesn’t work because I just get a vector with magnitude 1 but what I want is just move the camera to the clicked position so the magnitude can change.

Best Regards,  
Jez

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [June 5, 2019, 8:06am UTC](https://forum.babylonjs.com/t/create-a-directional-vector-with-2-position-vectors/3685/5 "2019-06-05T08:06:21Z")

</div>

Yes, if A has position vector a, and B has position vector b then the vector from A to B is b - a and don’t normalize.

---

<div class="post-metadata">

**Author:** ![Jez](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jez/32/2219_2.png) [@Jez](https://forum.babylonjs.com/u/Jez)\
**Post date:** [June 5, 2019, 9:33am UTC](https://forum.babylonjs.com/t/create-a-directional-vector-with-2-position-vectors/3685/6 "2019-06-05T09:33:38Z")

</div>

okai okai thank you very much for your help 🙂
