0

所以我设计了一个走廊,我想让我的玩家穿过,但我似乎无法让一个物理体为它工作。玩家要么穿过墙壁,要么不能走下走廊,因为它会将物体视为一个巨大的立方体。我如何让物理体绕着物体移动。

let chessPieces = SCNScene(named: "art.scnassets/hallway.dae")

if let knight2 = chessPieces?.rootNode.childNodeWithName("Room", recursively: true) {

    knight2.position = SCNVector3Make(150, 30, 0)
    knight2.scale = SCNVector3Make(knight2.scale.x * 200, knight2.scale.y * 200, knight2.scale.z * 200)            
    var nodeScale = NSValue(SCNVector3:SCNVector3Make(200, 200, 200));
    var nodeGeometry = knight2.geometry;
    var shape = SCNPhysicsShape(geometry: nodeGeometry!, options: [SCNPhysicsShapeScaleKey:nodeScale])
    knight2.physicsBody = SCNPhysicsBody(type:SCNPhysicsBodyType.Static, shape: shape)            
    knight2.physicsBody?.categoryBitMask = rockCategory

    knight2.physicsBody?.angularVelocityFactor = SCNVector3Make(0.0,0.0,0.0)
    knight2.physicsBody?.collisionBitMask = 3
    knight2.name = "Student"          
    knight2.physicsBody?.mass = 1000
    scene?.rootNode.addChildNode(knight2)
}
4

1 回答 1

0

SceneKit 物理实体对实体形状进行建模。如果你试图模拟一个被边界包围的开放空间——比如房间或走廊——单个物理体将无济于事。这将用一个不可通过的区域填充房间的体积,并且其他物理体(具有重叠的碰撞蒙版)将被迫离开该区域。

如果要创建一个由边界包围的开放空间,则需要为边界创建物理体。SceneKitVehicle示例代码说明了这样做,为房间的地板和墙壁创建单独的物理体,并为每个创建几何体。SCNFloorSCNBox

于 2015-02-18T21:17:19.570 回答