If parent Node will be moved, childnodes will followed.

Hi, guys. I have a problem with drag and rotate SCNNode in ARKit.

When I rotate or move the node. It just moves one child node. How can I wrap them into one parent node?
Can you help me? I'm so exhausted to find out the answer.

Replies

You can wrap all nodes into a parent node by using the SceneKit Editor -> Scene Graph -> Add a child node and move them into the parent.

I did. But when I use hitTest.first.node, the childnode will be touch, not all parts of the object.

Can you look at my code?

Here is my code when touching:

       let location = recognizer.location(in: sceneView)
        var hitTestOptions = [SCNHitTestOption: Any]()
        hitTestOptions[SCNHitTestOption.boundingBoxOnly] = true
        let hit=sceneView.hitTest(location, options: hitTestOptions).first
            print("You're dragging")
            guard let selectedNode=(hit?.node) as SCNNode? else { return }
            let transform = arHitTestResult.last?.worldTransform
            let newPosition = float3((transform?.columns.3.x)!, ((transform?.columns.3.y)!), (transform?.columns.3.z)!)
            selectedNode.simdPosition = newPosition
            sceneView.scene.rootNode.addChildNode(selectedNode)
       

I did it. Thank you so much.