我正在尝试创建一个具有多个身体部位的蛇,可以向左和向右移动。我用了一个大头针,但在蛇停下来的时候,身体继续移动,没有停止。我弄乱了最大和最小角度,和扭矩,但似乎没有工作。我应该用不同类型的关节吗?
对不起,我不能登录到我的其他帐户,但这里的代码。基本上,第二部分晃动得很厉害。我希望增加7-8个零件,但它们只是不停地摇晃,特别是在移动"头"之后。当我移动蛇时,我想要一个流畅的"俯冲"动作。
self.physicsWorld.gravity = CGVectorMake(0, -100)
self.physicsWorld.contactDelegate = self
head.size = CGSize(width: 25,height: 25)
head.physicsBody = SKPhysicsBody(texture: head.texture, size: head.size)
head.position = CGPointMake(100,400)
head.anchorPoint = CGPoint(x: 0.5, y: 1)
head.physicsBody!.dynamic = false
head.zPosition = 3
self.addChild(head)
var p1 = SKSpriteNode(imageNamed: "snakeBodyPart.png")
p1.size = CGSize(width: 25,height: 25)
p1.physicsBody = SKPhysicsBody(texture: p1.texture, size: p1.size)
p1.position = CGPointMake(100,380)
p1.anchorPoint = CGPoint(x: 0.5, y: 1)
p1.physicsBody!.dynamic = true
addChild(p1)
var joint = SKPhysicsJointPin.jointWithBodyA(head.physicsBody, bodyB: p1.physicsBody, anchor: CGPoint(x: CGRectGetMidX(head.frame), y: CGRectGetMinY(head.frame) + 10))
joint.upperAngleLimit = 0.1
joint.rotationSpeed = 0.1
self.physicsWorld.addJoint(joint)