作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我似乎无法弄清楚如何使用 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/
我似乎无法弄清楚如何使用 SCNTransformConstraint 来限制节点的 Z 值。这是我目前所拥有的。 let constraint = SCNTransformConst
我是一名优秀的程序员,十分优秀!