使球从网(子节点)上掉下来并摆动一下? (PhysicsBody / ARKit)

时间:2018-06-27 15:28:32

标签: ios swift xcode scenekit arkit

想知道篮球的制作方法如何通过网坠落并进行摇摆运动?球上已经有重力,但由于形状,它不会完全掉入网中。我需要以某种方式使球网具有柔韧性,以使球(球体)从轮辋顶部进入时能够通过。球只停止了1/3的距离。我正在Xcode上尝试使用iOS ARKit(SceneKit)。谢谢!

Screenshot Photo

  1. 球代码。

    let ball = SCNSphere(radius: 0.15)
    
    let material = SCNMaterial()
    material.diffuse.contents = UIImage(named: "basketballSkin.png")
    ball.materials = [material]
    
    let ballNode = SCNNode(geometry: ball)
    ballNode.position = cameraPosition
    
    let physicsShape = SCNPhysicsShape(node: ballNode, options: nil)
    let physicsBody = SCNPhysicsBody(type: .dynamic, shape: physicsShape)
    
    ballNode.physicsBody = physicsBody
    
    let forceVector:Float = 6
    ballNode.physicsBody?.applyForce(SCNVector3(x: cameraOrientation.x * forceVector,y: cameraOrientation.y * forceVector ,z: cameraOrientation.z * forceVector), asImpulse: true)
    
    sceneView.scene.rootNode.addChildNode(ballNode)
    

  1. 除背板节点外的网络代码。

    func addBackboard(){
    guard let backboardScene = SCNScene(named: "art.scnassets/hoop.scn") else{
        return
    }
        guard let backboardNode = backboardScene.rootNode.childNode(withName: "backboard", recursively: false) else{
            return
    }
    
        backboardNode.position = SCNVector3(x: 0,y: 0.5,z: -3)
    
        let physicsShape = SCNPhysicsShape(node : backboardNode, options: [SCNPhysicsShape.Option.type: SCNPhysicsShape.ShapeType.concavePolyhedron])
        let physicsBody = SCNPhysicsBody(type: .static, shape: physicsShape)
    
        backboardNode.physicsBody = physicsBody
    
        sceneView.scene.rootNode.addChildNode(backboardNode)
        currentNode = backboardNode
    

-路德

1 个答案:

答案 0 :(得分:0)

两个值得尝试的解决方案。一种非常酷的方法是使用Particle System创建网络,而不是经典的网络,您可以放置​​一些更具创意,更复杂和生动的示例。球网可以随风移动,然后被球击中改变

其他解决方案可能是创建一个节点序列,以表示球通过槽时球网所遭受的不同变化,该序列应在球接触球网内部的某个透明节点时开始。

外观好,挑战如此之大