SpriteKit 'pinned' 属性 允许y轴改变位置

SpriteKit 'pinned' property allows y-axis change in position

我有一个 SpriteKit 游戏,球在其中弹跳,与其他物体相互作用。

其中一个对象是一个微调器,它应该绕着它的中心旋转,但是没有改变它的x/y位置。它应该是静止的,除了旋转。

根据 Apple 的 documentationnode.physicsBody.pinned = true 应该完全符合我的要求,因此:

"the node’s position is fixed relative to its parent. The node’s position cannot be changed by actions or physics forces. The node can freely rotate around its position in response to collisions or other forces."

然而,事实并非如此。 发生的事情是,当一个球直接击中它时,旋转器的 y 轴位置会发生变化 -- 短暂地向下移动,然后弹回到正确的位置。

我的微调器代码(请假设所有变量都已定义):

      for i in 0..<spinners.count {
            let spinnerNode = SKSpriteNode(texture: texture)
            
            spinnerNode.position = CGPoint(x: spinners[i].minX, y: spinners[i].minY)
            
            spinnerNode.size = CGSize(width: spinners[i].width, height: spinners[i].height)
            
            spinnerNode.physicsBody = SKPhysicsBody(texture: spinnerNode.texture!, size: CGSize(width: spinners[i].width, height: spinners[i].height))
            spinnerNode.physicsBody?.isDynamic = true
            spinnerNode.physicsBody?.affectedByGravity = false
            
            spinnerNode.physicsBody?.pinned = true
            
            addChild(spinnerNode)
        }

为什么我的微调器节点在与球碰撞时会垂直移动?为什么 .pinned 没有像宣传的那样工作?

感谢您的帮助!

我通过将旋转节点的 mass 设置为略大于球节点的值来解决问题。

node.physicsBody?.mass = 6.0