当用户长按屏幕时,我一直试图将多维数据集向前移动。我无法使其平稳移动。有什么方法可以仅将其向前移动(沿负方向)并更新场景中每一帧的位置?
这是我到目前为止所拥有的:
var carLocation = SCNVector3(x:0, y: 0, z:-0.01)
func setupScene() {
sceneView = self.view as? SCNView
scene = SCNScene(named: "art.scnassets/Map.scn")
sceneView.scene = scene
let holdRecognizer = UILongPressGestureRecognizer()
holdRecognizer.addTarget(self, action: #selector(GameViewController.hold(recognizer:)))
sceneView.addGestureRecognizer(holdRecognizer)
}
@objc func hold(recognizer: UILongPressGestureRecognizer) {
print("Held down!")
let position = recognizer.location(in: sceneView)
carLocation = SCNVector3(x:0, y: 0, z:-0.01)
carNode.physicsBody?.velocity += carLocation
}
答案 0 :(得分:0)
我对您的印刷品进行了计数,以便您可以看到LongPress会重复自己……“很多”,这可能不是您长期想要的。因此,假设您创建了以下内容:
let p = SCNPhysicsBody(type: .dynamic, shape: nil)
p.isAffectedByGravity = false
shipNode.physicsBody = p
这将使您的对象平滑地前后移动。
@objc func hold(recognizer: UILongPressGestureRecognizer) {
print("Held down! \(count)")
count += 1
shipNode.physicsBody?.velocity = SCNVector3Make(0.0, 0, 0.51)
}
@objc func handleTap(_ gestureRecognize: UIGestureRecognizer) {
shipNode.physicsBody?.velocity = SCNVector3Make(0.0, 0, -0.51)
}
除非那里有很多物体,否则我看不出它变慢的任何原因。设置scnView.showsStatistics = true可以查看您的FPS。希望您不是要在模拟器中运行Scenekit吗?