Getting an SCNPhysicsVehicle's Position

*爱你&永不变心* 提交于 2019-12-01 15:30:09

Scene Kit automatically updates the position of the node that owns an SCNPhysicsBody based on the physics simulation, so SCNNode.position is the right property to look for.

The catch is that there are actually two versions of that node in play. The one you typically access is called the "model" node. It reflects the target values for properties you set, even if you set those properties through an animation. The presentationNode reflects the state of the node currently being rendered — if an animation is in progress, the node's properties have intermediate values, not the target values of the animation.

Actions, physics, constraints, and any scene graph changes you make inside update/render loop methods directly target the "presentation" version of your scene graph. So, to read node properties that have been set by the physics simulation, get the presentationNode for the node you're interested in (the node that owns the vehicle's chassisBody physics body), then read the presentation node's position (or other properties).

tekodragoon

I have the same problem with my player node. I move it with applyForce (to manage collision detection). But when i check node position after some movement, the node position has not move (presentation node is the actual position as rickster write in his answer) I manage to update the scnNode.position with renderer loop You have to set position of your node with the presentationNode position.

node.position = node.presentationNode.position

Set this into renderer(_: updateAtTime) and your node position will sync with any animation you made to the physicsBody

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!