Update SCNPhysicsBody when scaling SCNNode

核能气质少年 提交于 2019-12-11 07:28:09

问题


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?


回答1:


Try this

let nodeScale = SCNVector3(0.5,0.5,0.5)

 boxNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.static, shape: SCNPhysicsShape(geometry: box, options:  [SCNPhysicsShape.Option.scale: nodeScale]))


来源:https://stackoverflow.com/questions/48153416/update-scnphysicsbody-when-scaling-scnnode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!