简体   繁体   English

如何在不重置SCNNode位置的情况下重置SCNNode的SCNPhysicsBody?

[英]How can I reset an SCNNode's SCNPhysicsBody without resetting the SCNNode's position?

I have a sceneKit app for iOS. 我有一个iOS的SceneKit应用。 I have an SCNPhysicsBody attached to an SCNNode. 我有一个SCNPhysicsBody附加到SCNNode。 I set the .physicsBody to nil, make some changes the SCNNode and then set the .physicsBody to a new SCNPhysicsBody or to a copy of the original SCNPhysicsBody. 我将.physicsBody设置为nil,对SCNNode进行了一些更改,然后将.physicsBody设置为新的SCNPhysicsBody或原始SCNPhysicsBody的副本。 In either case, the SCNNode resets its position to its initial position. 无论哪种情况,SCNNode都会将其位置重置为其初始位置。

How can I reset the .physicsBody and keep the SCNNode in the same position so it continues on its trajectory? 如何重设.physicsBody并将SCNNode保持在相同位置,使其沿其轨迹继续前进?

When your physics affects node position its original position (that was assigned to node position property) stays same, presentation node position is changed. 当您的物理影响节点位置时,其原始位置(分配给节点position属性的原始位置)保持不变, 表示节点的位置也会更改。 All transformations (rotation/scale/translate) works that way. 所有转换(旋转/缩放/平移)都以这种方式工作。

So you can do something something like this pseudocode: 因此,您可以执行类似以下伪代码的操作:

// 1. remember position of presentation node
var position = node.presentation.position;
// 2. do some changes on node, physics body, whatever
// 3. restore position (without losing original node position)
your_node.presentation.position = position
// ... or apply presentation position to original position
your_node.position = position

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM