Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Brayden Kness
12,492 PointsScene Kit Physics: Friction and Concave Polyhedrons
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?