Camera attached object get orientation flipped when attached to WebXR Anchor (playground included)

Hello, I am facing a bug apparently caused by a lack of orientation of an object that get worse when I try to apply rotation. How do you fix that ?

Playground :

Goal :
place an object in AR based on the camera position and orientation. When it is placed, the object is attached to a WebXR Anchor.

Issue :
when the object is attached to the anchor, it gets flipped randomly.

Intended behavior :
The behavior in the playground in 3D not immersive is the intended behavior.

Attempts at fixing :
I noticed that the rotation of the plane was never set. So I first tried to fix a rotation when adding to the camera, but the object is then not always facing the camera anymore when moving it around. Not ideal. I then tried to rotate it after dropping, but then it disappears…

How to reproduce :

  1. Open the playground anywhere
  2. click on spawn
  3. move the camera around
  4. click on place
  5. move the camera around
  6. Open the playground in a WebXR environment with anchors
  7. reproduce 2 to 4

Author note :
I am fairly new to babylonjs, so this might be super trivial, yet I could not find a mention of this neither on doc nor in the forum. Can you please help me ?

Hey Wellandr!

The plane mesh’s rotationQuaternion is null in this case because by default the rotation member is used, so you’re passing in undefined for the rotation in addAnchorAtPositionAndRotationAsync.

Try using camChild.rotation.toQuaternion() instead. See https://playground.babylonjs.com/#FNT826#26 for an example that works in WebXR.

1 Like

Thank you, that was indeed what I was missing. Thank’s a lot !!!