# Finding a Ray perpendicular to another

**URL:** <https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200>\
**Category:** Questions\
**Created:** [May 9, 2022, 2:20pm UTC](https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200 "2022-05-09T14:20:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dreadbond](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dreadbond/32/12494_2.png) [@Dreadbond](https://forum.babylonjs.com/u/Dreadbond)\
**Post date:** [May 9, 2022, 2:20pm UTC](https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200/1 "2022-05-09T14:20:39Z")

</div>

Hi everybody !

I need to do one simple thing … create a Ray from the camera target and going up, perpendicular to the camera forward ray.

 ![needed](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/e/1e1aeece3812cf86427ed1283c085c126b6983da.png)

I’ve read things about [rotation](https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions), but I’m not able to use them for Vector3 or Rays…

So here is my attempt to do this : [https://playground.babylonjs.com/#C0D5C5#5](https://playground.babylonjs.com/#C0D5C5#5)

I’m creating a “help” box, and a “helpUp” box attached to it (its child)  
When the camera moves, the boxes follows.

But as you can see, creating the ray from “help” to “helpUp” isn’t working. The coordinates are OK in the console, but for a reason, the Ray isn’t doing it well.

Could someone help me by either telling the magic formula to turn a Ray, or having the right coordinates ?

---

<div class="post-metadata">

**Author:** ![imerso](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/imerso/32/46445_2.png) [@imerso](https://forum.babylonjs.com/u/imerso)\
**Post date:** [May 9, 2022, 2:45pm UTC](https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200/2 "2022-05-09T14:45:04Z")

</div>

If I understood your question, the

`camera.getDirection(BABYLON.Vector3.Up())`

does what you want.

Here:

> **[Babylon.js Playground](https://playground.babylonjs.com/#C0D5C5%236)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Dreadbond](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dreadbond/32/12494_2.png) [@Dreadbond](https://forum.babylonjs.com/u/Dreadbond)\
**Post date:** [May 9, 2022, 2:51pm UTC](https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200/3 "2022-05-09T14:51:17Z")

</div>

Thanks @imerso but not really.  
If you look at the picture I just uploaded, the Ray must always be perpendicular to the forwardRay.

With your solution, if I move the camera to the up, the yellow ray is not perpendicular

> **[Babylon.js Playground](https://playground.babylonjs.com/#C0D5C5%237)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![imerso](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/imerso/32/46445_2.png) [@imerso](https://forum.babylonjs.com/u/imerso)\
**Post date:** [May 9, 2022, 2:54pm UTC](https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200/4 "2022-05-09T14:54:21Z")

</div>

Are you sure? Maybe I’m not understanding your question, but check this update – it is the same thing, but I added a plane for you to see the ray with a plane:

> **[Babylon.js Playground](https://playground.babylonjs.com/#C0D5C5%238)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

If that is not what you want, then I really did not understand what you want.

---

<div class="post-metadata">

**Author:** ![Dreadbond](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dreadbond/32/12494_2.png) [@Dreadbond](https://forum.babylonjs.com/u/Dreadbond)\
**Post date:** [May 9, 2022, 2:59pm UTC](https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200/5 "2022-05-09T14:59:38Z")

</div>

I see the plane, and its initialization is good !

But, move the camera, do you see the two transparent boxes ?  
I want the yellow ray to stay at their centers.

---

<div class="post-metadata">

**Author:** ![imerso](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/imerso/32/46445_2.png) [@imerso](https://forum.babylonjs.com/u/imerso)\
**Post date:** [May 9, 2022, 3:03pm UTC](https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200/6 "2022-05-09T15:03:19Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#C0D5C5%239)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Maybe I just forgot to update every frame?

---

<div class="post-metadata">

**Author:** ![Dreadbond](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dreadbond/32/12494_2.png) [@Dreadbond](https://forum.babylonjs.com/u/Dreadbond)\
**Post date:** [May 9, 2022, 3:07pm UTC](https://forum.babylonjs.com/t/finding-a-ray-perpendicular-to-another/30200/7 "2022-05-09T15:07:14Z")

</div>

YES !!!  
This is it, getting a relative direction from the first !

Didn’t know about direction.set() and getDirection(localAxis). Definitively need to dive in this…  
Thanks @imerso !
