3

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?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
user2252471
  • 289
  • 3
  • 9

1 Answers1

1

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.

Antonio Ciolino
  • 546
  • 5
  • 16
  • 1
    You don't even have to redesign the visible geometry of the board -- just give it an `SCNPhysicsShape` composed of multiple primitive shapes (like boxes) to serve as its collision surface. – rickster Jun 17 '15 at 19:13
  • Ok, so essentially create multiple slices of the board and arrange them in the shape of the board leaving a hole in the middle? – user2252471 Jun 21 '15 at 00:35