Reputation: 289
I am working on a cornhole game in Scene Kit and have encountered a bug with SCNPhysicsShape
and SCNPhysicsBody
friction. The board for the game is loaded through a .dae
file and is set as a SCNPhysicsShapeTypeConcavePolyhedron
. This allows the bean bag to fall through the hole however it seems to nullify the friction on the board. When the bean bag hits the board it slides right off despite have a friction value of 1.0 (the bean bag has a friction value of 1.0 as well). If I change the board to SCNPhysicsShapeTypeConvexHull
then the friction works but the bean bag does not fall through the hole.
Here is my custom board initialization:
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
And here is the custom initialization for the bean bag
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
These are both inside of init methods for classes that subclass SCNNode
My question is: how can I keep the board as a ConcavePolyhedron
and have the friction work at the same time?
Upvotes: 3
Views: 764
Reputation: 556
This might not be the best answer, but it would work. Redesign your board into multiple pieces, leaving a hole in the middle that is not part of a geometry.
Upvotes: 1