How do I grab the camera's world position in WebXR?

I can’t seem to find information on how to access the camera world position when in WebXR. Some sources seem to indicate I want to use .setFromMatrixPosition(camera.matrixWorld) but --EDIT-- it works.

There is a known issue in this context. All Object3D.getWorld*() methods do not work when presenting since they recompute the camera’s world matrix which currently produces wrong results. The details about this bug are explained in the following issue:

The workaround is indeed the usage of Vector3.setFromMatrixPosition():

cameraWorldPosition.setFromMatrixPosition( camera.matrixWorld );
1 Like

I presume you mean “matrixWorld” and not “worldMatrix”?

I don’t know what I was doing but yes, you’re correct. It seems to work (I was doing something wrong on my end).


Ops, you’re right. Let me fix the typo.

1 Like