2017-12-30 38 views
0

장면 킷에 간단한 로직을 만들려고하는데, 아직까지는 행운이 없습니다. 저는 두 구 사이에 구가 있습니다. 동적 인 물리학의 몸체와 두 개의 평면으로 이루어진 구체는 정적 인 물리 구조를 가지고 있습니다. 비행기의 한쪽을 향해 구에 힘을 가하고 있습니다. 충돌시 구가 평면에서 반대 방향으로 튀어 나오지만 많은 힘을 잃어 버립니다. 충돌시 힘을 유지하기 위해 어떻게 만들 수 있습니까? 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

: 이것은 내 변화에 게임 템플릿 엑스 코드에서 생성되는 viewDidLoadCode입니다.

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

은 신체의 bounciness ""이 속성은 시뮬레이션 ". 1.0의 보상은 몸이 충돌시에 에너지를 잃지 않는다는 것을 의미합니다. 예를 들어 평평한 표면에 떨어 뜨린 공은 떨어지는 높이로 되돌아옵니다. 0.0의 반발은 신체가 충돌 한 후에 튀지 않는다는 것을 의미합니다. 1.0 이상의 보상은 시체가 충돌시에 에너지를 얻게합니다. 기본 손해율은 0.5입니다. "

또한 .friction 및 .rollingFriction 속성을 줄여야 할 수도 있습니다.