代码之家  ›  专栏  ›  技术社区  ›  Prashant Tukadiya

施力后ARKit获取节点位置

  •  0
  • Prashant Tukadiya  · 技术社区  · 7 年前

    how to track the position of a node after applying force in Arkit 1.5

    我有一个节点(SCNSphere),我在其中应用了force。节点具有 dynamic SCNNode 使用 physicsBody?.applyForce 一切都很好

    问题是在使用武力之后 动态 身体在不断下降 我要追踪那个位置

    renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) 我打印 position 属于 SCN节点 但它每次都显示相同的位置,为什么Y位置不减少,因为它是向下的?

    就像

    <SCNNode: 0x280f29500 'ball' pos(-0.165368 0.3 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child> <SCNNode: 0x280f29500 'ball' pos(-0.165368 0.2 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child> <SCNNode: 0x280f29500 'ball' pos(-0.165368 0.1 -0.809096) | geometry=<SCNSphere: 0x280619380 | radius=0.150> | no child>

    如何添加节点

            let ballWithOrientation = getNewBallNode() // return ball node + position
            let ballNode = ballWithOrientation.ball // it is the SCNNode
            self.sceneView.scene.rootNode.addChildNode(ballNode ?? SCNNode()) // Added to the scene 
            let cameraPosition =  self.sceneView.pointOfView?.worldFront
    
            let target =  SCNVector3(Double(cameraPosition?.x ?? 1) * forceVector,Double (cameraPosition?.y  ?? 1) * forceVector,Double(cameraPosition?.z ?? 1) * forceVector) // Vector of direction 
            let throwSpeed = self.calculateBestThrowSpeed(origin: ballNode!.position, target:target , timeToTarget: 0.66)  Calculated vector with velocity 
            ballNode?.physicsBody?.applyForce(throwSpeed, asImpulse: true) // apply force 
    

    问题 施力后如何跟踪SCNNode的世界位置?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Prashant Tukadiya    7 年前

    我找到了非常简单的解决办法

    open var presentation: SCNNode { get }
    

    这个属性 SCNNode 将为您提供当前节点的演示

    ballNode.presentation.position 将为您提供节点的当前位置和所有动画(力)

    Apple Docs

    使用隐式动画(请参见SCNTransaction)更改节点属性时,这些节点属性将立即设置为其目标值,即使已设置动画的节点内容似乎从旧属性值转换为新属性值。在动画场景中,它维护一个称为表示节点的节点副本,该节点的属性反映了当前影响该节点的任何飞行中动画所确定的临时值。

    希望对发现类似问题的人有所帮助

    推荐文章