好的,在这里与斯威夫特的 ARKit 合作并试图抓住这个 -

对于我的游戏控件,我希望能够控制当用户手指在屏幕上向下时 SCNNode 正朝着的点(在 3d 空间中的位置),这意味着由 touchesBegan func 启动。

我希望它像苹果公司的狐狸游戏一样带着操纵杆,但在 AR 中:https://developer.apple.com/library/content/samplecode/Fox/Introduction/Intro.html

我的主要问题是我的 SCNAction 的移动位置似乎没有在 touchesMoved 上正确更新,而且我需要 SCNNode 以相同的速度移动到该位置而不管它离开多远。

这是我的,它工作但不正确:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        guard let touch = touches.first else { return }

        let results = sceneView.hitTest(touch.location(in: sceneView), types: [ARHitTestResult.ResultType.featurePoint])
        guard let hitFeature = results.last else { return }

        checkIfNodeTapped(touches: touches, node: theDude.node)
        theDude.moveToPos(pos: getARPos(hitFeature: hitFeature))
    }

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {

        guard let touch = touches.first else { return }

        let results = sceneView.hitTest(touch.location(in: sceneView), types: [ARHitTestResult.ResultType.featurePoint])
        guard let hitFeature = results.last else { return }

        theDude.updateWalkTo(pos: getARPos(hitFeature: hitFeature))

    }

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
//        if virtualObjectManager.virtualObjects.isEmpty {
//
//            return
//        }
//        virtualObjectManager.reactToTouchesEnded(touches, with: event)

        //Remove move actions
        theDude.stopMoving()

    }

func updateWalkTo(pos: SCNVector3)
    {
        walkAction = SCNAction.move(to: pos, duration: 1)
    }

    func moveToPos(pos: SCNVector3)
    {
        walkAction = SCNAction.move(to: pos, duration: 1)
        self.node.runAction(walkAction, forKey: "walk")

    }

    func stopMoving()
    {
        self.node.removeAction(forKey: "walk")
    }

其中 walkAction 只是一个定义的 SCNAction。如何解决这个问题,以便节点向用户手指在屏幕上的任何位置(转换为 AR 点)运行?