gpt4 book ai didi

ios - 如何使用 SCNTransformConstraint 来限制节点的 Z 值?

转载 作者:搜寻专家 更新时间:2023-10-31 08:34:01 26 4
gpt4 key购买 nike

我似乎无法弄清楚如何使用 SCNTransformConstraint 来限制节点的 Z 值。这是我目前所拥有的。

        let constraint = SCNTransformConstraint(inWorldSpace: true, withBlock:{
node, matrix in

var newMatrix = matrix
let currentNode = node as SCNNode
if (currentNode.presentationNode().position.z > 0.0) {
newMatrix.m43 = 0.0
}

return newMatrix
})

ship.constraints = [constraint]

有了上述约束,当我向它的 physicsBody 施加力时,ship 不会移动。任何帮助将不胜感激。

最佳答案

是的。这个也让我有点难过。

问题出在矩阵上。据Developer documentation关于 SCNMatrix4(矩阵)参数:

If the node is affected by an in-progress animation, this value reflects the currently visible state of the node during the animation (rather than its target state that will be visible when the animation completes).

取而代之的是:

var newMatrix = matrix

你真的想要:

var newMatrix = node.transform

这似乎是要应用于节点的当前变换。

我知道这是一个老问题,但这在 SCNTransformConstraint 的搜索结果中接近顶部。嘿,迟到总比不到好,对吧?

关于ios - 如何使用 SCNTransformConstraint 来限制节点的 Z 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29859722/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com