2017-12-30 26 views
0

私はシーンキットで単純なロジックを作成しようとしていますが、これまでのところ運がありません。 私は球と2つの飛行機の間にあります。動的な物理的な体と2つの平面としての球体は静的な物理的な体を含んでいます。 私は球に面の1つに力をかけています。衝突すると、球は飛行機から反対方向に跳ね返りますが、力の損失が大きくなります。どのように私は衝突に力を維持するためにそれを作ることができます。 physicsbodyの反発プロパティを設定しscnnodeに衝突時に力を加えずに力を加える

override func viewDidLoad() { 
    super.viewDidLoad() 

    // create a new scene 
    let scene = SCNScene(named: "art.scnassets/ship.scn")! 

    // create and add a camera to the scene 
    let cameraNode = SCNNode() 
    cameraNode.camera = SCNCamera() 
    scene.rootNode.addChildNode(cameraNode) 

    // place the camera 
    cameraNode.position = SCNVector3(x: 0, y: 0, z: 15) 

    // create and add a light to the scene 
    let lightNode = SCNNode() 
    lightNode.light = SCNLight() 
    lightNode.light!.type = .omni 
    lightNode.position = SCNVector3(x: 0, y: 10, z: 10) 
    scene.rootNode.addChildNode(lightNode) 

    // create and add an ambient light to the scene 
    let ambientLightNode = SCNNode() 
    ambientLightNode.light = SCNLight() 
    ambientLightNode.light!.type = .ambient 
    ambientLightNode.light!.color = UIColor.darkGray 
    scene.rootNode.addChildNode(ambientLightNode) 

    // retrieve the ship node 
    let ship = scene.rootNode.childNode(withName: "sphere", recursively: true)! 




    // retrieve the SCNView 
    let scnView = self.view as! SCNView 

    // set the scene to the view 
    scnView.scene = scene 

    ship.physicsBody?.applyForce(SCNVector3(x: 100,y: 0, z: 0), asImpulse: false) 


    // allows the user to manipulate the camera 
    scnView.allowsCameraControl = true 

    // show statistics such as fps and timing information 
    scnView.showsStatistics = true 

    // configure the view 
    scnView.backgroundColor = UIColor.black 

    // add a tap gesture recognizer 
    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:))) 
    scnView.addGestureRecognizer(tapGesture) 
} 

the scn file

simulator

答えて

0

:これは私の変化にゲームのテンプレートにXcodeで生成されるviewDidLoadCodeです。

https://developer.apple.com/documentation/scenekit/scnphysicsbody/1514740-restitution

体の弾み 『「このプロパティは、シミュレートします』。 1.0の回復は、衝突時に身体がエネルギーを失うことを意味します。たとえば、平らな面に落としたボールは、落ちた高さに跳ね返ります。 0.0の反発は、衝突後に身体が跳ね返ってこないことを意味します。 1.0より大きい回復は、身体を衝突させてエネルギーを得る原因となります。デフォルトの反発力は0.5です。

また、.frictionプロパティと.rollingFrictionプロパティを減らすこともできます。

関連する問題