Moving an SCNNode in ARKit doesn’t work as expected



I was trying to make an app which first detects a plane and then puts a SCNPlane over it. There are a few nodes as a child node to the plane and I want to move them with a long press by the user using the long press gesture recogniser. Here’s the code:



@available(iOS 12.0, *)
    @objc func move( _ recognizer: UILongPressGestureRecognizer){

        guard let recognizerView = recognizer.view as? ARSCNView else { return }

        let touch = recognizer.location(in: recognizerView)

        let hitTestResult = self.sceneView.hitTest(touch)
        guard let modelNodeHit = hitTestResult.first?.node else { return }

       if !(modelNodeHit.categoryBitMask == BodyType.dynamicObjects.rawValue) { return }

        let hitResult = self.sceneView.hitTest(touch, types: .existingPlane)
        if !hitResult.isEmpty {
            guard let hitResult = hitResult.last else { return }
            modelNodeHit.position = SCNVector3Make(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, hitResult.worldTransform.columns.3.z)


The plane is rotated 90deg in order to make it a horizontal plane. As told above, when I long press any child node, it just goes up and some right or left and not really moves. However, this sometimes works on the parent plane node. What could be the reason? Please help..



Powered by WPeMatico

You may also like...

Comments are closed.