本文介绍了缩放 SCNNode 时更新 SCNPhysicsBody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道当节点缩放时 SCNPhysicsBody 不会缩放,但我还没有找到解决这个问题的好方法.我想缩放节点,然后在缩放节点后将 SCNPhysicsBody 更新为节点.
I know that SCNPhysicsBody dont scale when the node scale, but I haven't found a great solution to fix this. I want to scale the node and then update the SCNPhysicsBody to node after scaling it.
let box = SCNBox(width: 0.2, height: 0.3, length: 0.4, chamferRadius: 0.1)
box.firstMaterial?.diffuse.contents = UIColor.blue
var boxNode = SCNNode(geometry: box)
boxNode.scale = SCNVector3(0.5, 0.5, 0.5)
boxNode.position.x += 0.5
boxNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.static, shape: SCNPhysicsShape(geometry: box, options: nil))
sceneView.scene.rootNode.addChildNode(boxNode)
有没有人想出一个很好的解决方案来解决这个问题?
Has anyone come up with a great solution to this problem?
推荐答案
试试这个
let nodeScale = SCNVector3(0.5,0.5,0.5)
boxNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.static, shape: SCNPhysicsShape(geometry: box, options: [SCNPhysicsShape.Option.scale: nodeScale]))
这篇关于缩放 SCNNode 时更新 SCNPhysicsBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!