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

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

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

Am I missing a better solution?

Hi J!

How `bout this playground?

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

Later, if you want to use a BabylonJS 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.

1 Like

Hi again!

Here’s a BJS GUI version.

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

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. :slight_smile: