沿后摄像头指向的方向对SCNSphere施加力

时间:2018-06-29 13:46:42

标签: swift scenekit arkit

我已经阅读了许多stackoverflow答案,但是都没有添加示例代码,我可以从中获得帮助

我尝试过

func createBall (with velocityMultiplier:Float = 0 ,touchLocation:CGPoint = .zero) {

    let geo = SCNSphere(radius: 1)
    var node = SCNNode(geometry: geo)
    node.geometry?.firstMaterial?.diffuse.contents = UIColor.cyan
    node = self.update(node, withGeometry: geo, type: .dynamic)
    node.physicsBody?.isAffectedByGravity = true
    node.physicsBody?.allowsResting = true

    let (direction,position) = getUserVector()
    node.position = position
    node.simdTransform = (sceneView.session.currentFrame?.camera.transform)!

    self.sceneView.scene.rootNode.addChildNode(node)


    let force = simd_make_float4(0, 0,-3,0)
    let rotatedForce = simd_mul((sceneView.session.currentFrame?.camera.transform)!, force)

    let vectorForce = SCNVector3(x:rotatedForce.x, y:rotatedForce.y, z:rotatedForce.z)


    node.physicsBody?.applyForce(vectorForce , asImpulse: true)

}

工作正常球从中心扔出

在这里,如果我更改let force = simd_make_float4(0, 2,-3,0)的Y或X位置,则没有从中心抛出球,而是从屏幕上抛出了球

我需要应用Y和Z位置来强制进行任何帮助

0 个答案:

没有答案