Je suis coincé avec un problème sur ARKit et j'ai besoin d'aide. Je fais une petite démo où je place une géométrie SCNTorus simple dans la scène et j'essaye de lancer une petite boule (SCNSphere) dans le trou du tore. Le problème est que la balle rebondit au milieu plutôt que de passer à travers. Il est le code pour le torus:ARKit: Balle ne passant pas par le trou SCNTorus
let ring = SCNTorus(ringRadius: 0.4, pipeRadius: 0.1)
ring.ringSegmentCount = 100
let ringMaterial = SCNMaterial()
ringMaterial.diffuse.contents = UIImage(named: "art.scnassets/Ball/BeachBallColor.jpg")
ring.materials = [ringMaterial]
let ringNode = SCNNode()
ringNode.position = SCNVector3(
x: location.worldTransform.columns.3.x,
y:location.worldTransform.columns.3.y + 0.8,
z: location.worldTransform.columns.3.z
)
ringNode.geometry = ring
let body = SCNPhysicsBody(type: SCNPhysicsBodyType.kinematic,
shape: nil)
body.categoryBitMask = CollisionTypes.wall.rawValue
body.collisionBitMask = CollisionTypes.beachball.rawValue
// body.contactTestBitMask = CollisionTypes.beachball.rawValue
body.isAffectedByGravity = false
body.mass = 0.5
ringNode.physicsBody = body
sceneView.scene.rootNode.addChildNode(ringNode)
Et pour la balle:
let node = SCNNode(geometry: sphere!)
node.renderingOrder = 10
let body = SCNPhysicsBody(type: SCNPhysicsBodyType.dynamic,shape: nil)
body.categoryBitMask = CollisionTypes.beachball.rawValue
body.collisionBitMask = CollisionTypes.solid.rawValue|CollisionTypes.wall.rawValue|CollisionTypes.beachball.rawValue
// body.contactTestBitMask = CollisionTypes.fireball.rawValue|CollisionTypes.wall.rawValue
body.isAffectedByGravity = true
body.mass = 0.5
body.restitution = 0.75
body.damping = 0.1
body.friction = 0.8
node.physicsBody = body
double possible: https://stackoverflow.com/q/27391763/957768 – rickster