SceneKit Cylinder物理奇怪的行为

时间:2015-09-23 09:28:45

标签: swift scenekit

我试图创造某种保龄球,但在添加物理之后它就会掉下来然后再站起来。也许它与群众中心有关,但我无法弄清楚......

我已将代码缩减为简单的柱面和带有SCNFloor的场景

func createPin(scene: SCNScene)
{
    let cylinder = SCNCylinder(radius: 0.04, height: 0.21)
    let sh1 = SCNPhysicsShape(geometry: cylinder, options: nil)
    let cylinder2 = SCNCylinder(radius: 0.035, height: 0.21)
    let sh2 = SCNPhysicsShape(geometry: cylinder2, options: nil)

    let sphereTransforms = [
        SCNMatrix4MakeTranslation(0,0.1,0)
        //SCNMatrix4MakeTranslation(0,0.1,0)
    ]
    let transforms = sphereTransforms.map {
        NSValue(SCNMatrix4: $0)
    }

    let demo = SCNNode()
    let node1 = SCNNode(geometry: cylinder)
    node1.transform=SCNMatrix4MakeTranslation(0,0.1,0)
    demo.addChildNode(node1)
    //let node2 = SCNNode(geometry: cylinder2)
    //node2.transform=SCNMatrix4MakeTranslation(0,0.3,0)
    //demo.addChildNode(node2)


    let shape3 = SCNPhysicsShape(shapes: [sh1], transforms: transforms)
    let body3 = SCNPhysicsBody(type: SCNPhysicsBodyType.Dynamic, shape: shape3)
    demo.physicsBody=body3

    let trans=SCNMatrix4MakeTranslation(1,1,0.5)
    let rot = SCNMatrix4MakeRotation((Float)(90*M_PI/180.0), 1, 0, 0)
    demo.transform=SCNMatrix4Mult(rot, trans)

    scene.rootNode.addChildNode(demo)
}

有什么猜测吗?

0 个答案:

没有答案