Attach object to AR camera

Hello,

So I have this simple AR project that just load and place a flower in the middle of the scene, I want to “grab” it and move it around. I want to attach it to the camera to move it and release it using this code:

let flipflop = true;
  session.addEventListener("select", (event) => {
    if (flower) {
      if(flipflop){
        camera.attach(flower);
        flipflop = !flipflop;
      }else{
        camera.remove(flower);
        flower.matrixWorld.decompose( flower.position, flower.quaternion, flower.scale );
        scene.add(flower);
        flipflop = !flipflop;
      }
    }
  });

The problem is when I attach it to the camera the flower disappear, yet when I click again it will detach normally and reappear in the scene! (Knowing that before attaching, I can see the flower!) any idea why the flower is disappearing when attached to the camera?

Thanks.

Maybe camera is no added to the scene, so when you move the flower to the camera, it is not a part of the scene anymore.

1 Like

@PavelBoytchev yep, I copied most of the script from a past project of mine and it seems that I’ve missed the camera … it didn’t accrue to me due to the AR app worked normally as if the camera is in the scene, thanks.

1 Like