在SceneKit中,我遇到了两个动态球体碰撞的问题,当一个动态球体快速碰撞到另一个时,它正在通过它的内部。当我将physicsWorld.timeStep
的值从1/60
增加到1/300
之后,Spheres的碰撞就变得完美了。但是,在此刻,如果球体撞击到静态墙,则它开始沿墙滑动(像粘性的一样),而不是从墙反射出来。撞到墙后,球开始失去那么多能量。
当timeStep为1/60时,即使在如此低的速度下,球仍会在墙壁上弹跳,而不是粘在墙壁上。物理参数受时间步长影响的是墙或球体的什么参数?
墙壁参数;
let ballMass: CGFloat = 0.08
physicsWorld.timeStep = 1/300
let wallGeometry = SCNPlane(width: (maxX - minX), height: wallHeight)
wallGeometry.firstMaterial?.diffuse.contents = UIColor.red
wallGeometry.firstMaterial?.isDoubleSided = true
let shapeWallGeometry = SCNPhysicsShape(geometry: wallGeometry, options: nil) //su an lik bir ise yaramiyor
let wallNode = SCNNode(geometry: wallGeometry)
wallNode.position = SCNVector3( x: Float(xCenter), y: Float(minY-cushionHeight/2), z: Float(cushionHeight)/2 )
wallNode.physicsBody = SCNPhysicsBody(type: .static, shape: shapeWallGeometry)
wallNode.physicsBody?.restitution = 0.82
wallNode.physicsBody?.friction = 0.91
wallNode.physicsBody?.categoryBitMask = PhysicsCategory.WallType.rawValue | PhysicsCategory.GravityType.rawValue
wallNode.physicsBody?.collisionBitMask = PhysicsCategory.BallOneType.rawValue | PhysicsCategory.BallTwoType.rawValue | PhysicsCategory.BallThreeType.rawValue | PhysicsCategory.GravityType.rawValue
wallNode.physicsBody?.contactTestBitMask = PhysicsCategory.BallOneType.rawValue | PhysicsCategory.BallTwoType.rawValue | PhysicsCategory.BallThreeType.rawValue
self.rootNode.addChildNode(wallNode)