ARKit - Get User's Position

How can I get the position of the user?

Replies

I mean in 3D coordinate system in ARKit. I am assuming that in AR mode we as a user are the camera. How can I get the x, y and z position of the user?

Hi to get the uers location you use the "frame.camera.transform" this is basically a world matrix representing the camera. It will either be the last column or last row in the matrix (I cant remember the matrix order used by these systems). It will give you values like x,y,z,1 when you take the last column (or row). Just ignore the 1.


Anyway, that should give you enough to work it out.

You are correct.


It gives you the camera transform with the last column having (x,y,z), but I believe this is from the initial position at z, so you need to calculate the altitude.


Also, you absolutely must have a scene present to receive any relevant information, but perhaps this is obvious to most people. We aren't using scenekit, and instead using our own rendering engine, so we had to create a fake scene to get this transform.

Code Block
        let camPosition = frame.camera.transform.columns.3
        node.position = SCNVector3(camPosition.x, camPosition.y, camPosition.z)

  • With RealityKit:

    let camPosition = simd_make_float3(currentFrame.camera.transform.columns.3)

Add a Comment