# Best way to attach a mesh to the camera rotation around the y-axis

**URL:** <https://forum.babylonjs.com/t/best-way-to-attach-a-mesh-to-the-camera-rotation-around-the-y-axis/368>\
**Category:** Questions\
**Created:** [December 20, 2018, 11:45pm UTC](https://forum.babylonjs.com/t/best-way-to-attach-a-mesh-to-the-camera-rotation-around-the-y-axis/368 "2018-12-20T23:45:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhadenfeldt](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhadenfeldt](https://forum.babylonjs.com/u/jhadenfeldt)\
**Post date:** [December 20, 2018, 11:45pm UTC](https://forum.babylonjs.com/t/best-way-to-attach-a-mesh-to-the-camera-rotation-around-the-y-axis/368/1 "2018-12-20T23:45:39Z")

</div>

I am trying to build a button that can be used to leave a scene at any time. The way it should work is to have a button always visible when the user looks down and also rotate as the user rotates the camera around the y-axis.

This is what I came up with: [Babylon.js Playground](https://www.babylonjs-playground.com/#M4ESSD)

My other idea would be different layer masks, but this solution above feels simpler.

Am I missing a better solution?

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [December 21, 2018, 12:31am UTC](https://forum.babylonjs.com/t/best-way-to-attach-a-mesh-to-the-camera-rotation-around-the-y-axis/368/2 "2018-12-21T00:31:55Z")

</div>

Hi J!

How `bout this [playground](https://www.babylonjs-playground.com/#M4ESSD#1)?

I inserted some comments. I hope I understand what you were looking-for.

Later, if you want to use a [BabylonJS GUI](https://doc.babylonjs.com/how_to/gui) button down there, that should be successful, too. You would probably put the AdvancedTexture (the basis of BJS GUI) on a plane… right where the sphere is, now.

Not sure about the background color on the plane. We might need to experiment with that.

If you need help with that, just holler. I hope I was helpful.

**ooops** I just realized that I haven’t done anything about .position, yet. Down-cursor the camera, and we leave the sphere behind. Oh no! I’ll work on another playground version, or maybe you/another can handle it. I assume you want to keep the camera and button… same distance apart, vertically. And, you don’t want the button to go under-ground, either. That’s going to be a challenge… if/when the camera moves-to 1 millimeter above ground. hmm.

I have an idea, though. By using a full-screen AdvancedTexture (BJS GUI)… and making a button that has a very large button.top… so it is off-screen on screen bottom, and then making button.top (sort of like marginTop in CSS)… REDUCE in value… as camera tilts-down, that might work. Weird. Maybe I’ll try it.

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [December 21, 2018, 1:26am UTC](https://forum.babylonjs.com/t/best-way-to-attach-a-mesh-to-the-camera-rotation-around-the-y-axis/368/3 "2018-12-21T01:26:58Z")

</div>

Hi again!

Here’s a BJS GUI version.

Badly coded, canvas resize could cause hell. But, it’s a proof of… something. 🙂

[https://www.babylonjs-playground.com/#M4ESSD#4](https://www.babylonjs-playground.com/#M4ESSD#4)

If you pan the camera round and round enough times, the button will start rotating around it’s z-axis… a tiny tiny bit. Sloppy math in my calibrations. Sorry. When Wingnut codes, it’s like a baby with a chainsaw. 🙂
