Aligning Axis Mesh Attached to camera to the ground plane

Hello everyone. Thank you Daves for making this. And thank you community for giving me the opportunity to ask a question.

https://www.babylonjs-playground.com/#KWRA33

The playground above has an axis / xyz co ordinate mesh that is to align with the ground plane.

The axis mesh is also parented to the camera.

I’ve been trying some things to have this axis to always have the same alignment to the ground plane but I cannot get it to play ball. Could anyone shed some light or help educate me?

Thank you.

Hey and welcome :slight_smile:

Which axis do you want to align with the mesh? Maybe it would be better to parent the axis with the ground?

Hello Deltakosh and thank you for the welcome.

The axis I want to use is the axis mesh in the import mesh - it may be changed visually and it’s fairly easy for me to place the pivot point where I want via 3d max.

Sadly I have to keep this axis parented to the camera - essentially as an indicator of what direction my camera is looking at in the scene.

So maybe I’ll try and ask it a different way. I’d like the orientation of this axis to be always aligned to the ground plane’s orientation - whilst it is attached to the camera. In essence: kind of like a 3D compass.

I do have the axis.rotation = camera.rotation. It kind of gives the illusion that it is working - but I feel that alignment to the ground plane would be better.

Sorry I was unclear :slight_smile: Which axis (X, Y, or Z) do you want to align? Or even better which plane (XY, YZ, YZ) ?

Oh apologies Deltakosh - it was likely me misunderstanding.

As my imagination sees it - I believe it is all the axis (XYZ) as we would be moving through 3D space.

I have been wondering about my axis.rotation = camera.rotation. I think it is nearly there - but only in inverse.

Perhaps this would work if I can reverse the values… hmmm. I’ll keep trying too.

Apologies - I may not be explaing this so well.

something like that maybe:
https://www.babylonjs-playground.com/#KWRA33#1 ?

Exactly like this!

Deltakosh be careful I never meet you or I’ll kiss you smack on the lips!

Thank you for this - I’ll study how you done it in more detail.

And well done on a wonderful board presence!

You legend

Haha:) it was my pleasure

https://www.babylonjs-playground.com/#LRGBFS#3

Ok I think I was too excited when I seen your last example @Deltakosh. It was close but not cigar. However thank you for your help so far - really. Rotations and orientations are still a dark art to me and I am slowly getting there.

So I’ve made up a new version with your code - and the axis is on the ground to show you all the problem.

Once the camera moves - the axis mesh moves with it - however I thought it would of always aligned to the floor. This was my bad as I indicated that this is what I wanted. It is close - but just not there yet.

Second problem is shown on this version https://www.babylonjs-playground.com/#LRGBFS#4

The axis is attached to the camera and once it rotates so far - it jumps back to another angle. The axis in theory should rotate 360 degrees, though I am aware it uses Yaw, Pitch and Roll so different values I believe from reading the documentation.

Thank you all again for your help

Honestly what you need a NOT to attach the axis to the camera :slight_smile:

Ah it’s what someone has asked me to do :slight_smile: I’m trying to sell them another approach like a second camera that shows the orientation. Hmmm. Pain!

If Billy does not change his mind you will have to fight against the complex forces of stacked rotations :slight_smile:

You need to get back to world (this is what my example did) and then apply the ground rotation (providing the ground stays at 0,0,0)

Very complicated if you want my thoughts

Yeah the ground wouldn’t move. But due to time constraints , I’m selling them that :slight_smile:

I’ll likely be back with silly questions.