SceneKit: Moving Reference SCNNode with panning

I have 2 scene that i drag into a new scene please see image for the setup.

What i’m trying to do is to move position of the Large_Needle with panning.

I’m referencing the large needle node like this:

var largeNeedle: SCNNode!
largeNeedle = scene.rootNode.childNode(withName: "Large_Needle", recursively: true)

Pan Gesture recognition and handler

let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.handlePanning(pan:)))

  @objc func handlePanning(pan: UIPanGestureRecognizer) {
    let touchPoint = pan.location(in: sceneView)
    if let hit = sceneView.hitTest(touchPoint, options: nil).first {
      if let name = {
        if name == "Large_Needle_Cap" || name == "Large_Needle" {
          let yPan = pan.velocity(in: sceneView).y/10000
          largeNeedle.runAction(SCNAction.moveBy(x: 0, y: yPan, z: 0, duration: 0.1))

But for some reason, the position of it don’t update. I also try using largeNeedle.position = SCNVector3(0, yoffset, 0) don’t work also. Can anyone tell me why it’s not working?

Need some debugging info. Does it ever get to " let yPan = …"?
Put a print statement there, so you know if it is finding the node or not.

If it does, what does it get for yPan? Print that value out too. Dividing by 10000 might be making yPan too small to show up.

Thank you for responding. I was able to solve the problem. i had an enum state to activate this. There were another function that overriding the state. all good now. Thanks again.

This topic was automatically closed after 166 days. New replies are no longer allowed.