title: ARKit - getting distance from camera to anchor
body: <p>I'm creating an anchor and adding it to my ARSKView at a certain distance in front of the camera like this:</p>
  
  <pre><code>func displayToken(distance: Float) {
          print("token dropped at: \(distance)")
          guard let sceneView = self.view as? ARSKView else {
              return
          }
  
          // Create anchor using the camera's current position
          if let currentFrame = sceneView.session.currentFrame {
              // Create a transform with a translation of x meters in front of the camera
              var translation = matrix_identity_float4x4
              translation.columns.3.z = -distance
              let transform = simd_mul(currentFrame.camera.transform, translation)
  
              // Add a new anchor to the session
              let anchor = ARAnchor(transform: transform)
              sceneView.session.add(anchor: anchor)
          }
      }
  </code></pre>
  
  <p>then the node gets created for the anchor like this:</p>
  
  <pre><code>func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -&gt; SKNode? {
          // Create and configure a node for the anchor added to the view's session.
          if let image = tokenImage {
              let texture = SKTexture(image: image)
              let tokenImageNode = SKSpriteNode(texture: texture)
              tokenImageNode.name = "token"
              return tokenImageNode
          } else {
              return nil
          }
      }
  </code></pre>
  
  <p>This works fine and I see the image get added at the appropriate distance. However, what I'm trying to do is then calculate how far the anchor/node is in front of the camera as you move. The problem is the calculation seems to be off immediately using fabs(cameraZ - anchor.transform.columns.3.z). Please see my code below that is in the update() method to calculate distance between camera and object:</p>
  
  <pre><code>override func update(_ currentTime: TimeInterval) {
          // Called before each frame is rendered
          guard let sceneView = self.view as? ARSKView else {
              return
          }
  
          if let currentFrame = sceneView.session.currentFrame {
              let cameraZ =  currentFrame.camera.transform.columns.3.z
              for anchor in currentFrame.anchors {
                  if let spriteNode = sceneView.node(for: anchor), spriteNode.name == "token", intersects(spriteNode) {
                      // token is within the camera view
                      //print("token is within camera view from update method")
                      print("DISTANCE BETWEEN CAMERA AND TOKEN: \(fabs(cameraZ - anchor.transform.columns.3.z))")
                      print(cameraZ)
                      print(anchor.transform.columns.3.z)
                  }
              }
          }
      }
  </code></pre>
  
  <p>Any help is appreciated in order to accurately get distance between camera and the anchor.</p>