【问题标题】:Node losing gravity after SCNActionSCNAction 后节点失去重力
【发布时间】:2019-10-31 01:46:15
【问题描述】:

我想放下一个物体,然后将它移回顶部,让它再次落下。第一部分正在工作,但随后节点似乎失去了重力并且不再下降。它看起来像它的物理体停留在地板上并且没有被 SCNActions 移动。解决方案是什么?谢谢

    let shape = SCNPhysicsShape(geometry: SCNBox(width: boxSize, height: 0.001, length: boxSize, chamferRadius: 0), options:nil)
    node.physicsBody = SCNPhysicsBody(type: .dynamic, shape: shape)
    ...
    SCNTransaction.begin()
    SCNTransaction.animationDuration = 5 
    let actions = SCNAction.sequence([
        SCNAction.move(to: SCNVector3(x: 0, y: 3, z: -2), duration: 1),
        SCNAction.rotate(by: .pi*2, around: SCNVector3(0,1,0), duration: 1)
    ])
    node.runAction(actions)
    //node.presentation.runAction(actions) //also not working
    SCNTransaction.commit()

【问题讨论】:

    标签: ios scenekit scnnode


    【解决方案1】:

    您必须通过调用-resetTransform 让物理模拟知道物理体已移动。

    【讨论】:

    • 谢谢,resetTransform 可以正常工作。不再需要 scnactions,因为它已经将对象重置到起始位置。如果我在 runAction 的 completionHandler 中使用它,我会得到不同的结果。要将其与 scnactions 结合起来,您可能需要自己调整转换。
    猜你喜欢
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    相关资源
    最近更新 更多