1 Reply
      Latest reply on Mar 28, 2018 4:38 PM by pj_mukh
      akash007 Level 1 Level 1 (0 points)

        Hey,

         

        So i'm using ARKit and detecting planes for the user to place an object. Once the plane is detected I display a button which when pressed run's the addBowlingLane() function to place it. The problem i'm having is when I walk away or around the object follows me which defeats the purpose of how i'm designing the app. So my question, is there any way for me to place an object and have it stay in that particular spot?

         

        Thanks!

         

        here's the relevant code

         

        1. func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
        2.     /
        3.     guard let planeAnchor = anchor as?  ARPlaneAnchor,
        4.     let planeNode = node.childNodes.first,
        5.     let plane = planeNode.geometry as? SCNPlane
        6.     else { return }
        7.   
        8.     /
        9.     planeNode.simdPosition = float3(planeAnchor.center.x, 0, planeAnchor.center.z)
        10.   
        11.     /
        12.     plane.width = CGFloat(planeAnchor.extent.x)
        13.     plane.height = CGFloat(planeAnchor.extent.z)
        14.     }
        15.   
        16.     func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        17.         /
        18.         guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
        19.       
        20.         if(!hasLaneBeenAnchored){
        21.             let plane = SCNPlane(width: CGFloat(planeAnchor.extent.x), height: CGFloat(planeAnchor.extent.z))
        22.             planeNode = SCNNode(geometry: plane)
        23.             planeNode.simdPosition = float3(planeAnchor.center.x, 0, planeAnchor.center.z)
        24.           
        25.             planeNode.eulerAngles.x = -.pi / 2
        26.           
        27.             planeNode.opacity = 0.25
        28.           
        29.             planeNode.geometry?.materials.first?.diffuse.contents = UIColor.init(red: 255.0/255.0, green: 146.0/255.0, blue: 237.0/255.0, alpha: 1.0)
        30.             node.addChildNode(planeNode)
        31.         }
        32.       
        33.     }
        34.   
        35.     @objc func addBowlingLane(){
        36.         let bScene = bowlingScene?.rootNode
        37.         bScene?.position = planeNode.position
        38.         sceneView.scene.rootNode.addChildNode(bScene!)
        39.         hasLaneBeenAnchored = true
        40.         instructionsLabel.text = "Back away from the\nbowling pins until you are at the edge of the bowling\n lane swipe up to bowl! "
        41.       
        42.         placeLaneBtn.isHidden = true
        43.     }
        
        
        • Re: SCNNode won't stay in place
          pj_mukh Level 1 Level 1 (0 points)

          I'm not sure why it won't stay in place but plenty of times a lot of my problems have been solved by attaching things to node instead of equating their positions.

          So instead of,

          bScene?.position = planeNode.position
          sceneView.scene.rootNode.addChildNode(bScene!)
          
          

           

          Maybe try

          planeNode.addChildNode(bScene)