The goal is to rotate a physics body around a point using angular velocity, not zRotation. Because of this, it seems necessary to add a second physics body (the one controlling the rotations), but changing the angular velocity on this parent doesn't move the child. In other words, the parent rotates, but the child remains in place.
我们的目标是利用角速度,而不是旋转,使一个物理物体围绕一个点旋转。正因为如此,似乎有必要添加第二个物理体(控制旋转的那一个),但是改变这个母体的角速度不会移动这个孩子。换句话说,父结点是旋转的,但子结点保持不变。
How can you rotate both the parent and child?
如何同时旋转父结点和子结点?
parent = SKNode()
sprite = SKSpriteNode(color: SKColor.whiteColor(), size: spriteSize)
sprite.position = CGPoint(x: 0, y: 50)
parent.addChild(sprite)
parent.physicsBody = SKPhysicsBody(rectangleOfSize: parentSize)
parent.physicsBody?.affectedByGravity = false
parent.physicsBody?.friction = 0
parent.physicsBody?.linearDamping = 0
parent.physicsBody?.angularDamping = 0
parent.physicsBody?.collisionBitMask = 0
sprite.physicsBody = SKPhysicsBody(rectangleOfSize: spriteSize)
sprite.physicsBody?.affectedByGravity = false
sprite.physicsBody?.friction = 0
sprite.physicsBody?.linearDamping = 0
sprite.physicsBody?.angularDamping = 0
sprite.physicsBody?.categoryBitMask = bitMask
sprite.physicsBody?.collisionBitMask = 0
parent.physicsBody?.angularVelocity = 2.0
1 个解决方案
#1
1
You can try to create joint between parent and child before setting angular velocity
在设置角速度之前,可以尝试在父结点和子结点之间创建关节
let fixedJoint = SKPhysicsJointFixed()
fixedJoint.bodyA = parent.physicsBody
fixedJoint.bodyB = sprite.physicsBody
self.physicsWorld.addJoint(fixedJoint)
#1
1
You can try to create joint between parent and child before setting angular velocity
在设置角速度之前,可以尝试在父结点和子结点之间创建关节
let fixedJoint = SKPhysicsJointFixed()
fixedJoint.bodyA = parent.physicsBody
fixedJoint.bodyB = sprite.physicsBody
self.physicsWorld.addJoint(fixedJoint)