Swift 如何在检测到的平面上移动虚拟对象
我试图在检测到的平面上移动带有动态物理体的虚拟对象,但移动后它开始跳跃和摆动 我已使用运动学physicBody在检测到的曲面上添加了floorNode 这是我的密码 func didPan(uu手势:ThresholdPanGesture){ 开关状态{ 案例.开始:Swift 如何在检测到的平面上移动虚拟对象,swift,virtual,arkit,Swift,Virtual,Arkit,我试图在检测到的平面上移动带有动态物理体的虚拟对象,但移动后它开始跳跃和摆动 我已使用运动学physicBody在检测到的曲面上添加了floorNode 这是我的密码 func didPan(uu手势:ThresholdPanGesture){ 开关状态{ 案例.开始: if let object = objectNodeInteracting(with: gesture, in: sceneView) { if object.name == "plane
if let object = objectNodeInteracting(with: gesture, in: sceneView) {
if object.name == "plane"{
return
}
selectedCube = object
}
let holdPoint = gesture.location(in: self.sceneView)
let result = self.sceneView.hitTest(holdPoint, types: .estimatedHorizontalPlane)
if (result.count == 0) {
return;
}
let hitResult = result.first
let transform = hitResult?.worldTransform
let dist = SCNVector3.init((transform?.columns.3.x)!, (transform?.columns.3.y)!, (transform?.columns.3.z)!)
prevusPonit = dist
PCoordx = (result.first?.worldTransform.columns.3.x)!
PCoordz = (result.first?.worldTransform.columns.3.z)!
case .changed:
if selectedCube == nil {
return
}
let holdPoint = gesture.location(in: self.sceneView)
let result = self.sceneView.hitTest(holdPoint, types: .estimatedHorizontalPlane)
if (result.count == 0) {
return;
}
let hitResult = result.first
let transform = hitResult?.worldTransform
if let coordx = result.first?.worldTransform.columns.3.x{
if let coordz = result.first?.worldTransform.columns.3.z{
let action = SCNAction.moveBy(x: CGFloat(coordx-PCoordx), y: 0.0, z: CGFloat(coordz-PCoordz), duration: 0.01)
SCNTransaction.begin()
selectedCube!.parent!.runAction(action)
SCNTransaction.commit()
PCoordx = coordx
PCoordz = coordz
}
}
gesture.setTranslation(CGPoint.zero, in: sceneView)
break
case .ended:
break
default:
}
}