我正在使用Scene Kit中的玉米孔游戏,遇到了SCNPhysicsShape
和SCNPhysicsBody
摩擦的错误。游戏的主板通过.dae
文件加载,并设置为SCNPhysicsShapeTypeConcavePolyhedron
。这允许豆袋通过孔落下,但它似乎使板上的摩擦无效。当豆袋撞到纸板时,尽管摩擦值为1.0(豆袋的摩擦值也为1.0),它仍会立即滑下。如果我将电路板更换为SCNPhysicsShapeTypeConvexHull
,则摩擦力会起作用,但豆袋不会从孔中掉落。
这是我的自定义电路板初始化:
let geo = nodeWithFile("board.dae").geometry!
geo.materials = [SCNMaterial()]
geo.firstMaterial!.diffuse.contents = "wood_texture.png"
geo.firstMaterial!.diffuse.wrapS = SCNWrapMode.Repeat
geo.firstMaterial!.diffuse.wrapT = SCNWrapMode.Repeat
geo.firstMaterial!.diffuse.mipFilter = SCNFilterMode.Linear
self.geometry = geo
self.position = position
self.rotation = SCNVector4Make(1, 0, 0, -CFloat(degreesToRadians(65.0)))
let shape = SCNPhysicsShape(geometry: geo, options: [SCNPhysicsShapeTypeKey: SCNPhysicsShapeTypeConcavePolyhedron])
self.physicsBody = SCNPhysicsBody(type: .Static, shape: shape)
self.physicsBody!.restitution = 0.0
self.physicsBody!.rollingFriction = 1.0
self.physicsBody!.friction = 1.0
这是bean包的自定义初始化
let geo = SCNBox(width: 20.0, height: 4.0, length: 20.0, chamferRadius: 5.0)
self.geometry = geo
self.position = position
self.geometry!.firstMaterial!.diffuse.contents = UIColor.blueColor()
let shape = SCNPhysicsShape(geometry: geo, options: [SCNPhysicsShapeTypeKey: SCNPhysicsShapeTypeBoundingBox])
self.physicsBody = SCNPhysicsBody(type: .Dynamic, shape: shape)
self.physicsBody!.restitution = 0.0
self.physicsBody!.rollingFriction = 1.0
self.physicsBody!.friction = 1.0
这些都属于子类SCNNode
我的问题是:如何将电路板保持为ConcavePolyhedron
并同时进行摩擦?
答案 0 :(得分:1)
这可能不是最好的答案,但它会起作用。将您的电路板重新设计成多个部件,在中间留下一个不属于几何图形的孔。