Search code examples
positionarkitscnnodeplanearanchor

Node's world position is always are origin - ARKit anchor


I am just trying to find world position and rotation of nodes after I detect and add planes to my AR scene.

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
  if !(anchor is ARPlaneAnchor) {
        return
    }
  let plane = //to visualise planes
  node.addChildNode(plane)
  print("Node : \(node.worldPosition)"
 }

but node.worldPosition always returns a SCNVector3(x: 0.0, y: 0.0, z: 0.0). Looks like the local position. Only the anchor gives its respective world position. I want to be able to transform the node according to the world transformations. Thanks in advance.


Solution

  • tldr: Print node.worldPosition inside renderer(_:didUpdate:for:)

    You are using renderer(_:didAdd:for:). Think of this as where you initially respond to a fresh new node on a new anchor. The new node hasn't yet been updated with relevant information. Adding a child plane to this new node as you did would be a good response.

    In contrast, renderer(_:didUpdate:for:) is used to respond to actual updates on the node. This is when we get to see the previously added node behave as we expect. That's why you are seeing unexpected values.