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
- func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
- /
- guard let planeAnchor = anchor as? ARPlaneAnchor,
- let planeNode = node.childNodes.first,
- let plane = planeNode.geometry as? SCNPlane
- else { return }
- /
- planeNode.simdPosition = float3(planeAnchor.center.x, 0, planeAnchor.center.z)
- /
- plane.width = CGFloat(planeAnchor.extent.x)
- plane.height = CGFloat(planeAnchor.extent.z)
- }
- func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
- /
- guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
- if(!hasLaneBeenAnchored){
- let plane = SCNPlane(width: CGFloat(planeAnchor.extent.x), height: CGFloat(planeAnchor.extent.z))
- planeNode = SCNNode(geometry: plane)
- planeNode.simdPosition = float3(planeAnchor.center.x, 0, planeAnchor.center.z)
- planeNode.eulerAngles.x = -.pi / 2
- planeNode.opacity = 0.25
- 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)
- node.addChildNode(planeNode)
- }
- }
- @objc func addBowlingLane(){
- let bScene = bowlingScene?.rootNode
- bScene?.position = planeNode.position
- sceneView.scene.rootNode.addChildNode(bScene!)
- hasLaneBeenAnchored = true
- instructionsLabel.text = "Back away from the\nbowling pins until you are at the edge of the bowling\n lane swipe up to bowl! "
- placeLaneBtn.isHidden = true
- }