如何将实体移回其初始位置

时间:2020-04-17 19:46:03

标签: ios swift arkit realitykit reality-composer

在对球施加线性脉冲和扭矩之后,我试图将球移回其初始位置。

从Reality Composer加载场景时,我将球的初始变换存储在这里

Experience.loadTestSphereAsync { (result) in
            switch result {
            case .success(let anchor):
                anchor.generateCollisionShapes(recursive: true)
                self.testSphereAnchor = anchor
                self.ball?.physicsBody?.mode = .static
                self.arView.scene.anchors.append(self.testSphereAnchor)
                self.ballStartTransform = self.testSphereAnchor.ball?.transform
                self.targetStartTransform = self.testSphereAnchor.target?.transform
                self.addTapGestures()
            case .failure(let error):
                fatalError(error.localizedDescription)
            }
        }

要将球移回原始位置,我正在这样做

func didPressRestartButton() {
        ball?.clearForcesAndTorques()
        ball?.physicsBody?.mode = .static
        ball?.move(to: ballStartTransform!, relativeTo: nil, duration: 0.3)
    }

球并没有回到原始位置,而是冻结了它所在的位置。

1 个答案:

答案 0 :(得分:0)