嘿在下面,我创建了一个普通球体,用于测试游戏场景/世界中是否具有物理场。所以我只是将球放在场景/世界中,这是完美的。它受重力影响。因此,然后我尝试对.scn文件执行完全相同的操作。我将其物理性质等同于跌落到重力的测试球。但是男人不动重力设置为-9.8以模拟常规重力
码:

  //----Test-Circle-here--------------------

    var sphere1: SCNNode!
    let sphereGeometry = SCNSphere(radius: 10.5)
    let sphereMaterial = SCNMaterial()
    let collisionCapsuleRadius = CGFloat(0.4 - 0.4) * 0.4
    let collisionCapsuleHeight = CGFloat(0.4 - 0.4)
    sphereMaterial.diffuse.contents = UIColor.greenColor()
    sphereGeometry.materials = [sphereMaterial]
    sphere1 = SCNNode(geometry: sphereGeometry)
    sphere1.position = SCNVector3(x: 1.0, y: 0.05, z: 0.05)

    //----Giving it a physics---------

    sphere1.physicsBody?.affectedByGravity = true
    sphere1.physicsBody?.friction = 0
    sphere1.physicsBody?.restitution = 1 //bounceness of the object
    sphere1.physicsBody?.angularDamping = 1 // rotationess
    sphere1.physicsBody = SCNPhysicsBody(type: .Dynamic, shape:SCNPhysicsShape(geometry: SCNCapsule(capRadius: collisionCapsuleRadius, height: collisionCapsuleHeight), options:nil))
    scnView.scene!.rootNode.addChildNode(sphere1)

在男人下方停留在同一地点,无论如何
     class Character {

let node = SCNNode()
init() {

    let GuyScene = SCNScene(named: "art.scnassets/FoxMan2.scn")
    let characterTopLevelNode: SCNNode = GuyScene!.rootNode.childNodeWithName("Guy", recursively: true)!
    let collisionCapsuleRadius = CGFloat(0.4 - 0.4) * 0.4
    let collisionCapsuleHeight = CGFloat(0.4 - 0.4)
    characterTopLevelNode.position = SCNVector3(x: 10.0, y: 0.0, z: 0.0)

    //----Giveing it a physics---------

    characterTopLevelNode.physicsBody?.affectedByGravity = true
    characterTopLevelNode.physicsBody?.friction = 0
    characterTopLevelNode.physicsBody?.restitution = 1 //bounceness of the object
    characterTopLevelNode.physicsBody?.angularDamping = 1 // rotationess
    characterTopLevelNode.physicsBody = SCNPhysicsBody(type: .Dynamic, shape:SCNPhysicsShape(geometry: SCNCapsule(capRadius: collisionCapsuleRadius, height: collisionCapsuleHeight), options:nil))
    node.addChildNode(characterTopLevelNode)

 }
}

enter image description here

enter image description here

最佳答案

检查并确保characterTopLevelNode实际上是您认为的节点(名称不匹配很常见)。在这种情况下,这通常是问题。您似乎将characterTopLevelNode添加为node的子级,但从未将node添加为正在显示的场景的子级。

另一件事,在创建物理实体之前,请勿在物理实体上设置选项。

例如:sphere1.physicsBody = SCNPhysicsBody(type: .Dynamic, ...sphere1.physicsBody.affectedByGravity = truesphere1.physicsBody.friction = 0sphere1.physicsBody.restitution = 1sphere1.physicsBody.angularDamping = 1

关于ios - 在SceneKit XCODE SWIFT中将简单物理应用于.scn对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38648718/

10-13 04:04