Search code examples
swiftcamerascenekit

Child object not following default camera in SceneKit


In a project, I have attached a SCNPlane to the default camera provided as allowsCameraControl is set to true, like so:

scnView.pointOfView?.addChildNode(plane)

Then the plane is placed right in front of the default camera:

plane.position = SCNVector3(x: 0, y: 0, z: -5)

When I debug the scene though, it shows the plane at the correct position, initially. However, the plane does not stay in front of the camera but rather at the initial position when the default cameras position is altered via user touch input.

Does anyone have an idea what could cause the misunderstanding here?


Solution

  • The problem was, that at the time

    scnView.pointOfView?.addChild(plane)
    

    was executed, the actual poV of the scene was still the old camera and not the generated one by allowsCameraControl. poV switches to the generated one as soon as the user makes first touch input.